Chapter 1: An Introduction to Visual Basic 2012

Slides:



Advertisements
Similar presentations
Chapter 1: An Introduction to Visual Basic 2012
Advertisements

© by Pearson Education, Inc. All Rights Reserved.
Visual Basic 2010 How to Program. © by Pearson Education, Inc. All Rights Reserved.2.
© by Pearson Education, Inc. All Rights Reserved. continued …
Chapter 2 –Visual Basic, Controls, and Events
 2006 Pearson Education, Inc. All rights reserved Introduction to the Visual C# 2005 Express Edition IDE.
Chapter 1: An Introduction to Visual Basic.NET Programming with Microsoft Visual Basic.NET, Second Edition.
Using the Visual Basic Editor Visual Basic for Applications 1.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
1 Introduction to the Visual Studio.NET IDE Powerpoint slides modified from Deitel & Deitel.
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Word Project 8 Working with Macros and Visual Basic for Applications (VBA)
Chapter 2 –Visual Basic, Controls, and Events
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter One An Introduction to Visual Basic 2010.
Microsoft Visual Basic 2012 CHAPTER TWO Program and Graphical User Interface Design.
Microsoft Visual Basic 2005: Reloaded Second Edition
IE 411/511: Visual Programming for Industrial Applications
Tutorial 1: An Introduction to Visual Basic.NET1 Tutorial 1 An Introduction to Visual Basic.NET.
Chapter 1: An Introduction to Visual Basic 2005 Programming with Microsoft Visual Basic 2005, Third Edition.
Teacher: Ms. Olifer MICROSOFT VISUAL STUDIO 2010: PROPERTIES OF WINDOWS FORM OBJECT.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 2 Creating a User Interface.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 3 Welcome Application Introduction to Visual Programming.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Chapter Two Designing Applications Programming with Microsoft Visual Basic th Edition.
Chapter Two Creating a First Project in Visual Basic.
Chapter 2 – Introduction to the Visual Studio .NET IDE
Microsoft Visual Basic 2010 CHAPTER TWO Program and Graphical User Interface Design.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to the Visual Studio.NET IDE Outline 2.1Introduction 2.2Visual Studio.NET Integrated.
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter One An Introduction to Visual Basic 2008.
Chapter 3 I Need a Tour Guide (Introduction to Visual Basic 2010) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Tutorial 1: An Introduction to Visual Basic.NET1 Tutorial 1 An Introduction to Visual Basic.NET.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 3 Building an Application in the Visual Basic.NET Environment.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
Addison Wesley is an imprint of © 2011 Pearson Addison-Wesley. All rights reserved. Chapter 2 Creating Applications with Visual Basic.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
 2007 Pearson Education, Inc. All rights reserved Introduction to the Visual Basic Express 2005 IDE.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
 You won’t write a single line of program code.  Instead, you’ll use visual programming techniques.  Visual Studio processes your actions (such as mouse.
Programming with Microsoft Visual Basic 2012 Chapter 1: An Introduction to Visual Basic 2012.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter One An Introduction to Visual Basic 2008.
Chapter 4: Do-It-Yourself Designing (Designing Interfaces)
Dive Into® Visual Basic 2010 Express
Chapter 3: I Need a Tour Guide (Introduction to Visual Basic 2012)
Chapter 1: An Introduction to Visual Basic .NET
Visual Basic.NET Windows Programming
Microsoft Visual Basic 2005: Reloaded Second Edition
Chapter 2: The Visual Studio .NET Development Environment
Chapter 1: An Introduction to Visual Basic 2015
Chapter 2 – Introduction to the Visual Studio .NET IDE
3.01 Apply Controls Associated With Visual Studio Form
Programming with Microsoft Visual Basic th Edition
Program and Graphical User Interface Design
1. Introduction to Visual Basic
3.01 Apply Controls Associated With Visual Studio Form
Chapter 1: An Introduction to Visual Basic 2015
Introduction to the Visual C# 2005 Express Edition IDE
Using Procedures and Exception Handling
Chapter 2 Visual Basic Interface
Program and Graphical User Interface Design
Chapter 2 – Introduction to the Visual Studio .NET IDE
Hands-on Introduction to Visual Basic .NET
CIS16 Application Development Programming with Visual Basic
Building an Application in the Visual Basic .NET Environment
Presentation transcript:

Chapter 1: An Introduction to Visual Basic 2012

Lesson A Objectives After studying Lesson A, you should be able to: Start and customize Visual Studio 2012 Create a Visual Basic 2012 Windows application Manage the windows in the IDE Set the properties of an object Restore a property to its default setting Save a solution Close and open an existing solution Programming with Microsoft Visual Basic 2012

The Splash Screen Application Figure 1-1 Splash screen for the Red Tree Inn Programming with Microsoft Visual Basic 2012

The Splash Screen Application (cont.) To start Visual Studio Professional 2012: Click Start and point to All Programs Select Microsoft Visual Studio 2012 Click Start Visual Studio Click WINDOW (視窗) on the menu bar Click Reset Window Layout (重設視窗配置) Click Yes at the prompt to restore the default layout You can also select a different window layout using TOOLS→ Options on the menu bar Figure 1-2 Microsoft Visual Studio Professional 2012 startup screen Programming with Microsoft Visual Basic 2012

Setting Window Layout Figure 1-3 Options dialog box Programming with Microsoft Visual Basic 2012

The Splash Screen Application (cont.) To create a Visual Basic 2012 Windows application: Click FILE on the menu bar, and then click New Project Enter Splash Project in the Name Box Locate a folder to store the project Select Create Directory for Solution Programming with Microsoft Visual Basic 2012

The Splash Screen Application (cont.) Figure 1-4 Completed New Project dialog box in Visual Studio Professional 2012 Programming with Microsoft Visual Basic 2012

The Splash Screen Application (cont.) Figure 1-5 Solution and Visual Basic project Programming with Microsoft Visual Basic 2012

The Splash Screen Application (cont.) Managing the Windows in the IDE To open the Properties Window: Click VIEW on the menu bar, and then click Properties Window Or mouseover the Solution Explorer tab if the window is auto-hidden To close a window: Use the Close button on the window’s title bar To minimize a window to a tab: Click the Auto Hide (push-pin) button on the Solution Explorer window Programming with Microsoft Visual Basic 2012

The Splash Screen Application (cont.) Figure 1-6 Current status of the windows in the IDE Programming with Microsoft Visual Basic 2012

Windows Form Designer Window Used to create a graphical user interface (GUI) Windows Form object Create a UI by adding objects Buttons Text boxes The title bar contains a default caption minimize, maximize, and close buttons Figure 1-7 Windows Form Designer window Programming with Microsoft Visual Basic 2012

Solution Explorer Window Displays a list of projects contained in the current solution and items contained in each project Source file (原始檔) A file containing program instruction (code) Form file (表單檔) : a kind of source file Contains code associated with a form The first form’s code is stored in Form1.vb The second form’s code is stored in Form2.vb 列出專案內各檔案 Figure 1-8 Solution Explorer window V.S. Programming with Microsoft Visual Basic 2012

Properties Window Properties Object box Properties list Settings box Attributes of objects that determine appearance and behavior Object box Contains the name of the selected object Properties list Helps identify and access properties Settings box Shows the current values of properties Figure 1-9 Properties window V.S. Programming with Microsoft Visual Basic 2012

Properties of a Form File Using the Properties window to change a form file’s name Click Form1.vb Source file in Solution Explorer Window Click File Name in Properties list Type Splash Form.vb .vb extension identifies the file as a source file Press Enter Programming with Microsoft Visual Basic 2012

Properties of a Form File Programming with Microsoft Visual Basic 2012

Properties of a Windows Form Click Form1 in Form Designer Window System.Windows.Forms is the namespace that contains the Form class A class is a block of code that specifies an object’s appearance and behavior The period that separates each word in System.Windows.Forms.Form is called the dot member access Operator (成員取用運算子) Figure 1-11 Properties window showing a partial listing of the form’s properties Programming with Microsoft Visual Basic 2012

Important Properties of a Windows Form The Name Property Windows forms have a Name property Use it to refer to the form in the program code Naming conventions are used for clarity Hungarian notation for a variable frmSplash : “frm” indicates a form (data type of the variable), and “Splash” is the purpose of the variable Camel case Enter the data type name of a VB object in lowercase and then capitalize the first letter of each subsequent word in the name Programming with Microsoft Visual Basic 2012

Important Properties of a Windows Form The Text Property The Text property controls the text displayed in the form’s title bar The default text for the Text property of Form 1 is Form1 Change the default name to something meaningful The Name property is used by the programmer The Text property is read by the user when the application is running Programming with Microsoft Visual Basic 2012

Important Properties of a Windows Form The StartPosition Property The computer uses form’s StartPosition property to determine form’s initial execution position on the screen Splash screens usually appear in the middle of the screen Choose CenterScreen for the StartPosition WindowsDefaultLocation CenterScreen Programming with Microsoft Visual Basic 2012

Important Properties of a Windows Form The Font Property A font is the general shape of a character Font styles include regular, bold, and italic Font sizes (8, 10, 12, etc.) are in points, with 1 point equaling 1/72 of an inch The recommended font for applications is Segoe (pronounced SEE-go) This is Segoe UI, Size 18 Programming with Microsoft Visual Basic 2012

Important Properties of a Windows Form The Size Property A form can be sized by dragging the sizing handles that appear around it You also can size an object by selecting it and then pressing and holding down the Shift key as you press the up, down, right, or left arrow key on the keyboard You also can set the object’s Size property, which contains two numbers, measured in pixels: The first number represents the width of the form The second number represents the height of the form Programming with Microsoft Visual Basic 2012

Setting and Restoring a Property’s Value Click BackColor in the Properties list and then click the list arrow in the Settings box Click the Custom tab and then click a red square to change the background color of the form to red Now, right-click BackColor in the Properties list and then click Reset on the context menu The background color of the form returns to its default setting Figure 1-12 Status of the form in the IDE Programming with Microsoft Visual Basic 2012

Saving, Closing, Opening, and Exiting a Solution Saving a Solution An asterisk (*) appears on the designer tab whenever you make a change to the form Save the solution by clicking FILE on the menu bar and then clicking Save All Closing the Current Solution Click FILE on the menu bar and then click Close Solution To exit Visual Studio 2012, click FILE on the menu bar and then click Exit Opening an Existing Solution Click FILE on the menu bar, and then locate and open the solution from the list of filenames available Programming with Microsoft Visual Basic 2012

Lesson A Summary Starting Visual Studio Configuring Visual Studio Creating a Visual Basic 2012 Windows application Resetting a window layout Closing and opening windows Auto-hiding a window Setting property values (name, text, location, font, size, background color) Saving, closing, and opening solutions Exiting Visual Studio 2012 練習 p. 21~24 Programming with Microsoft Visual Basic 2012

Lesson B Objectives After studying Lesson B, you should be able to: Add a VB control to a form Set the properties of a label, picture box, and button control Select multiple controls on the form Format multiple VB controls simultaneously Open the Project Designer window Start and end an application Enter code in the Code Editor window Terminate an application using the Me.Close() instruction Run the project’s executable file Programming with Microsoft Visual Basic 2012

The Toolbox Window Class Object Toolbox window (or toolbox (工具箱)) A pattern from which an object is created Object An instance (個例) of a class with particular settings for behaviors and attributes Toolbox window (or toolbox (工具箱)) Contains component tools for designing a user interface Each tool represents a class VB Controls are instantiated (初始化) using tools of toolbox VB Controls VB GUI objects that appear on a form Programming with Microsoft Visual Basic 2012

The Toolbox Window (cont.) Figure 1-13 Toolbox window showing the purpose of the Label tool Programming with Microsoft Visual Basic 2012

The Label Tool Used to create a label control Important properties Displays text that cannot be edited at run time Important properties Name property A unique name for a control Text property Specifies the value that appears in a label control Location property Specifies the location of a control on a form Includes an X value and a Y value Programming with Microsoft Visual Basic 2012

Figure 1-15 Label control added to the form The Label Tool (cont.) Figure 1-15 Label control added to the form Programming with Microsoft Visual Basic 2012

The Label Tool (cont.) Setting the Text Property Select the lblName control Click text in the Properties list Type Red Tree Inn Press Enter Select the lblMsg control Type A relaxing place to stay! Verify that the AutoSize property is set to True Programming with Microsoft Visual Basic 2012

The Label Tool (cont.) Setting the Location Property Select the lblName control Click Location in the Properties list Expand the Location property by clicking the plus box Type 315, 130 Press Enter Select the lblMsg control Type 315, 175 Programming with Microsoft Visual Basic 2012

Changing a Property For Multiple Controls A control inherits the font attribute of the form You may want to change the default values To simultaneously modify similar controls: Click one control and then press and hold the Ctrl key Click other similar control(s) in the form, or click and drag to group the controls Set the property value in the Properties list Programming with Microsoft Visual Basic 2012

Using the Format Menu The Format menu provides options to manipulate form controls Align: Aligns selected controls by left, right, top, or bottom borders Make Same Size: Makes the width and/or height of selected controls uniform Center in Form: Centers one or more controls Select as the first control the one whose size or location you want to match Called the reference control 練習 p. 30~34 Programming with Microsoft Visual Basic 2012

The PictureBox Tool Creates a picture box control Displays an image on a form Task box: Lists tasks associated with a picture box Use the task box to import an image into a project Size Mode : StretchImage A project’s resource file contains imported images Figure 1-17 Open task list for a picture box Figure 1-18 Completed Select Resource dialog box Programming with Microsoft Visual Basic 2012

The PictureBox Tool (cont.) Figure 1-19 Picture boxes added to the form 練習 p. 34~36 Programming with Microsoft Visual Basic 2012

The Button Tool Used to create a button control Used to perform an action when clicked Examples: OK and Cancel buttons Common means of exiting a Windows application: Exit option on the FILE menu Exit button Programming with Microsoft Visual Basic 2012

Starting and Ending an Application Startup form (啟動表單) Displays when an application is first started The Project Designer window specifies the startup form or the executable code to be run Right-click My Project in the Solution Explorer window and then click Open Or, click PROJECT on the menu bar and then click <project name> Properties Application tab Specify startup form Programming with Microsoft Visual Basic 2012

Starting and Ending an Application (cont.) Figure 1-20 Application pane in the Project Designer window Programming with Microsoft Visual Basic 2012

Starting and Ending an Application (cont.) Executable file A file that can be run outside of the IDE Its filename ends with .exe It is automatically created when a Visual Basic application is started Two ways to start an application in the IDE: Click DEBUG on the menu bar and then click Start Debugging Press F5 key 練習 p. 36~38 Programming with Microsoft Visual Basic 2012

The Code Editor Window Events Event procedure Code Editor window User actions such as click, right-click, mouse-over, … Event procedure A set of program instructions that are processed when an event occurs Code Editor window Provides templates for creating event procedures To open it, right-click the form and then click View Code Programming with Microsoft Visual Basic 2012

The Code Editor Window (cont.) Figure 1-22 Code Editor window opened in the IDE Programming with Microsoft Visual Basic 2012

The Code Editor Window (cont.) Class Name list box Lists names of objects (VB controls) included in the UI Method Name list box Lists appropriate events for the selected object To select a VB control’s event in the Code Editor window: Select the class name first Then select the method name Syntax The rules of a programming language Programming with Microsoft Visual Basic 2012

Class Name and Method Name List Boxes Class Name list box Method Name list box Programming with Microsoft Visual Basic 2012

Writing A Procedure Procedure header Procedure footer Keyword The first line in the code template for an event procedure Procedure footer The last line in the code template for an event procedure Keyword A word that has a special meaning in a programming language Color coded in the IDE procedure header procedure footer Programming with Microsoft Visual Basic 2012

Event Sub Procedure Sub procedure Keywords in a sub procedure block: A block of code that performs a specific task Keywords in a sub procedure block: Sub: Starts a sub procedure End Sub: Indicates the end of a sub procedure Private: Restricts the use of the procedure to the form where it appears The names of event sub procedure include the object (VB control) name and event name Example: btnExit_Click Programming with Microsoft Visual Basic 2012

Me.Close() Instruction and IntelliSense Method A predefined procedure Can be called (or invoked) when needed Me.Close() method Causes the current form to close If it is the only form in an application, the application terminates IntelliSense feature Provides appropriate selections as pop-up lists when coding Type the first few letters of your choice Then use the arrow keys to select an item in the list 練習 p. 38~42 Programming with Microsoft Visual Basic 2012

The IntelliSense feature Figure 1-25 List displayed by the IntelliSense feature Programming with Microsoft Visual Basic 2012

Lesson B Summary To add a control to a form, use a tool from the toolbox Use the label control for text that users cannot edit You can set the properties of multiple controls simultaneously To start and stop an application in the IDE, use DEBUG on the menu bar Use the Code Editor window to display an object’s event procedures The Me.Close() method closes the current form at run time Programming with Microsoft Visual Basic 2012

Lesson C Objectives After studying Lesson C, you should be able to: Set the properties of a timer control Delete a control from the form Delete code from the Code Editor window Code a timer control’s Tick event procedure Prevent the user from sizing a form Remove and/or disable a form’s Minimize, Maximize, and Close buttons Print an application’s code and interface Programming with Microsoft Visual Basic 2012

Using the Timer Tool Splash screens typically close automatically They do not usually contain an Exit button Use a timer control to close the splash screen Timer tool Used to create a timer control Timer control Processes code at regular (規律的) time intervals Does not appear on the user interface at run time Important properties Interval property Specified in milliseconds Enabled property Allows the timer to run if set to True Programming with Microsoft Visual Basic 2012

Using the Timer Tool (cont.) Tick event Occurs each time a timer interval has elapsed Condition: The timer must enabled Add code to the Tick event procedure Code will be run when the Tick event occurs Component tray (元件盤) A special area below the form design area in the IDE Stores controls not visible in the user interface at run time Programming with Microsoft Visual Basic 2012

Using the Timer Tool (cont.) Figure 1-29 Timer control placed in the component tray 練習 p. 48~50 Programming with Microsoft Visual Basic 2012

FormBorderStyle Property of a Form Determines the border style of a form Example settings: Sizable: Allows the user to change a form’s size by dragging its borders at run time FixedSingle: A fixed, thin border line None: No border Programming with Microsoft Visual Basic 2012

The MinimizeBox, MaximizeBox, and ControlBox Properties MinimizeBox property Determines whether the Minimize button appears on the form’s title bar MaximizeBox property Determines whether the Maximize button appears on the form’s title bar ControlBox property Determines if the title bar elements appear on the form Splash screens typically do not contain a title bar To remove a title bar, delete the contents of the form’s Text property Programming with Microsoft Visual Basic 2012

The MinimizeBox, MaximizeBox, and ControlBox Properties (cont.) Figure 1-31 Completed splash screen 練習 p. 50~51 Programming with Microsoft Visual Basic 2012

Printing the Application’s Code and Interface Printing the application’s code and user interface helps you understand and maintain the application To print the interface : Run the application Press Alt+Prnt Scrn on the keyboard Paste into Word or Paint and then print To print the code : Click the Splash Form.vb tab to make the Code Editor window the active window Click FILE on the menu bar, and then click Print to open the Print dialog box Programming with Microsoft Visual Basic 2012

Printing the Application’s Code and Interface (cont.) Figure 1-32 Print dialog box Programming with Microsoft Visual Basic 2012

Lesson C Summary The timer control processes code at specified intervals A form’s MinimizeBox and MaximizeBox properties enable or disable the Minimize and Maximize buttons on the form A form’s ControlBox property determines whether the icon and control buttons appear in the title bar A form’s FormBorderStyle property controls the appearance of the form’s border Print Visual Basic code from the Code Editor window Print the user interface from the designer window Programming with Microsoft Visual Basic 2012