Programming with Microsoft Visual Basic 2010 5th Edition Chapter One An Introduction to Visual Basic 2010 Lesson B Objectives After studying Lesson B, you should be able to: Add a control to a form Set the properties of a label, picture box, and button control Select multiple controls Center controls on the form Open the Project Designer window 2 Programming with Microsoft Visual Basic 2010, 5th Edition Lesson B Objectives (cont’d.) 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 3 Programming with Microsoft Visual Basic 2010, 5th Edition The Toolbox Window Class: Pattern from which object is created Object: Instance with behaviors and attributes Toolbox window (or toolbox) Contains tools for designing user interface Each tool represents class Controls are instantiated using tools from toolbox Controls: GUI objects that appear on a form 4 Programming with Microsoft Visual Basic 2010, 5th Edition The Toolbox Window (cont’d.) Figure 1-15 Toolbox window showing the purpose of the Label tool 5 Programming with Microsoft Visual Basic 2010, 5th Edition The Label Tool Label tool: Used to create label control Label control: Displays text that cannot be edited at run time Name property: Unique name for control Text property Specifies value that appears in label control Location property Specifies location of control on form Includes X value and Y value 6 Programming with Microsoft Visual Basic 2010, 5th Edition Figure 1-16 Label tool being dragged to the form Figure 1-17 Label control added to the form 7 Programming with Microsoft Visual Basic 2010, 5th Edition Changing a Property for Multiple Controls Control inherits the Font attribute of the form May want to change from default values To simultaneously modify similar controls Click one control and then press and hold Ctrl key Click other similar control(s) in form Or click and drag to group controls Set property value in Properties list 8 Programming with Microsoft Visual Basic 2010, 5th Edition Changing a Property for Multiple Controls (cont’d.) Figure 1-18 Label controls selected on the form 9 Programming with Microsoft Visual Basic 2010, 5th Edition Using the Format Menu Format menu: Options to manipulate form controls Align: Aligns selected controls by left, right, top, or bottom borders Make Same Size: Makes width and/or height of selected controls uniform Center in Form: Centers one or more controls Select as first control the one whose size or location you want to match Called reference control 10 Programming with Microsoft Visual Basic 2010, 5th Edition The PictureBox Tool PictureBox tool: Creates picture box control Picture box control: Displays image on form Task box: Lists tasks associated with picture box Use task box to import image into project Project’s resource file contains imported images 11 Programming with Microsoft Visual Basic 2010, 5th Edition Figure 1-19 Open task list for a picture box Figure 1-20 Completed Select Resource dialog box 12 Programming with Microsoft Visual Basic 2010, 5th Edition The PictureBox Tool (cont’d.) Figure 1-21 Image shown in the picture box 13 Programming with Microsoft Visual Basic 2010, 5th Edition The Button Tool Button tool: Used to create button control Button control: Used to perform action when clicked Examples: OK and Cancel buttons Common means of exiting a Windows application Exit option on File menu Exit button 14 Programming with Microsoft Visual Basic 2010, 5th Edition Starting and Ending an Application Startup form: Displays when application is first started Project Designer window: Specifies startup form or executable code to be run Right-click My Project in Solution Explorer window and then click Open Or, click Project on menu and then click <project name> Properties Application tab: Specify startup form 15 Programming with Microsoft Visual Basic 2010, 5th Edition Starting and Ending an Application (cont’d.) Figure 1-22 Application pane in the Project Designer window 16 Programming with Microsoft Visual Basic 2010, 5th Edition Starting and Ending an Application (cont’d.) Executable file: File that can be run outside of the IDE File name ends with .exe Automatically created when starting Visual Basic application Two ways to start application in IDE Click Debug on menu bar and then click Start Debugging Press F5 key 17 Programming with Microsoft Visual Basic 2010, 5th Edition Starting and Ending an Application (cont’d.) Figure 1-23 Result of starting the splash screen application 18 Programming with Microsoft Visual Basic 2010, 5th Edition The Code Editor Window Event: User action such as double-clicking Event procedure: Set of program instructions that are processed when event occurs Code Editor window Provides templates for creating event procedures To open Code Editor window Right-click form and then click View Code 19 Programming with Microsoft Visual Basic 2010, 5th Edition The Code Editor Window (cont’d.) Figure 1-24 Code Editor window opened in the IDE 20 Programming with Microsoft Visual Basic 2010, 5th Edition The Code Editor Window (cont’d.) To collapse or expand a region of code in the Code Editor window Click minus box to collapse code Click plus box to expand code Figure 1-25 Code collapsed in the Code Editor window 21 Programming with Microsoft Visual Basic 2010, 5th Edition The Code Editor Window (cont’d.) Class Name list box Lists names of objects included in UI Method Name list box Lists appropriate events for selected object To select a control’s event in code editor window Select class name first and then select method name Syntax Rules of programming language 22 Programming with Microsoft Visual Basic 2010, 5th Edition The Code Editor Window (cont’d.) Procedure header First line in code template for event procedure Procedure footer Last line in code template for event procedure Keyword Word that has special meaning in programming language Color-coded in IDE 23 Programming with Microsoft Visual Basic 2010, 5th Edition The Code Editor Window (cont’d.) Sub procedure Block of code that performs a specific task Keywords in a sub procedure block Sub: starts a sub procedure Private: restricts the use of the procedure to the form where it appears End Sub: indicates the end of a sub procedure Event sub procedure names include object name and event name Example: btnExit_Click 24 Programming with Microsoft Visual Basic 2010, 5th Edition The Me.Close() Instruction Method: Predefined procedure Can be called (or invoked) when needed Me.Close() method Causes current form to close If it is only form in application, the application terminates IntelliSense feature: Provides appropriate selections as pop- up lists Type first few letters of choice Then use arrow keys to select an item in list 25 Programming with Microsoft Visual Basic 2010, 5th Edition Figure 1-27 List displayed by the IntelliSense feature Figure 1-28 Completed Click event procedure for the btnExit control 26 Programming with Microsoft Visual Basic 2010, 5th Edition Lesson B Summary To add a control to a form, use tool from toolbox Use Label control for text that user cannot edit Can set properties of multiple controls simultaneously To start and stop an application in IDE, use the Debug menu choice Use Code Editor window to display object’s event procedures Me.Close() method closes the current form at run time 27 Programming with Microsoft Visual Basic 2010, 5th Edition True or False: The Me.Exit() method can be used to close the current form. 28 Programming with Microsoft Visual Basic 2010, 5th Edition False 29 Programming with Microsoft Visual Basic 2010, 5th Edition A(n) ____________________ control should be used to display text that the user cannot edit at run time. 30 Programming with Microsoft Visual Basic 2010, 5th Edition Label 31 Programming with Microsoft Visual Basic 2010, 5th Edition The rules of a programming language are called its ____________________. 32 Programming with Microsoft Visual Basic 2010, 5th Edition Syntax 33 Programming with Microsoft Visual Basic 2010, 5th Edition True or False: The Text property is only available for the label control 34 Programming with Microsoft Visual Basic 2010, 5th Edition False 35 Programming with Microsoft Visual Basic 2010, 5th Edition
© Copyright 2025 Paperzz