Upload
lauren-curtis
View
227
Download
0
Tags:
Embed Size (px)
Citation preview
Chapter OneAn Introduction to Visual Basic 2010
Programming with Microsoft Visual Basic 2010
5th Edition
Programming with Microsoft Visual Basic 2010, 5th Edition
Lesson B Objectives
2
After studying Lesson B, you should be able to:
Add a control to a formSet the properties of a label, picture box,
and button controlSelect multiple controlsCenter controls on the formOpen the Project Designer window
Programming with Microsoft Visual Basic 2010, 5th Edition
Lesson B Objectives (cont’d.)
3
Start and end an applicationEnter code in the Code Editor windowTerminate an application using the Me.Close() instruction
Run the project’s executable file
Programming with Microsoft Visual Basic 2010, 5th Edition
The Toolbox Window
4
Class: Pattern from which object is createdObject: Instance with behaviors and
attributesToolbox window (or toolbox)
Contains tools for designing user interfaceEach tool represents class Controls are instantiated using tools from
toolbox Controls: GUI objects that appear on a
form
Programming with Microsoft Visual Basic 2010, 5th Edition
The Toolbox Window (cont’d.)
5
Figure 1-15 Toolbox window showing the purpose of the Label tool
Programming with Microsoft Visual Basic 2010, 5th Edition
The Label Tool
6
Label tool: Used to create label controlLabel control: Displays text that cannot
be edited at run timeName property: Unique name for controlText property
Specifies value that appears in label controlLocation property
Specifies location of control on formIncludes X value and Y value
Programming with Microsoft Visual Basic 2010, 5th Edition
Figure 1-17 Label control added to the form
Figure 1-16 Label tool being dragged to the form
7
Programming with Microsoft Visual Basic 2010, 5th Edition
Changing a Property for Multiple Controls
8
Control inherits the Font attribute of the formMay want to change from default values
To simultaneously modify similar controls Click one control and then press and hold
Ctrl keyClick other similar control(s) in form
Or click and drag to group controlsSet property value in Properties list
Programming with Microsoft Visual Basic 2010, 5th Edition
Changing a Property for Multiple Controls (cont’d.)
9
Figure 1-18 Label controls selected on the form
Programming with Microsoft Visual Basic 2010, 5th Edition
Using the Format Menu
10
Format menu: Options to manipulate form controlsAlign: Aligns selected controls by left, right,
top, or bottom bordersMake Same Size: Makes width and/or
height of selected controls uniformCenter in Form: Centers one or more
controlsSelect as first control the one whose size or
location you want to match Called reference control
Programming with Microsoft Visual Basic 2010, 5th Edition
The PictureBox Tool
11
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 projectProject’s resource file contains imported
images
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.)
13
Figure 1-21 Image shown in the picture box
Programming with Microsoft Visual Basic 2010, 5th Edition
The Button Tool
14
Button tool: Used to create button controlButton control: Used to perform action
when clickedExamples: OK and Cancel buttons
Common means of exiting a Windows applicationExit option on File menu Exit button
Programming with Microsoft Visual Basic 2010, 5th Edition
Starting and Ending an Application
15
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 OpenOr, click Project on menu and then click
<project name> PropertiesApplication tab: Specify startup form
Programming with Microsoft Visual Basic 2010, 5th Edition
Starting and Ending an Application (cont’d.)
16
Figure 1-22 Application pane in the Project Designer window
Programming with Microsoft Visual Basic 2010, 5th Edition
Starting and Ending an Application (cont’d.)
17
Executable file: File that can be run outside of the IDEFile name ends with .exeAutomatically created when starting Visual
Basic applicationTwo ways to start application in IDE
Click Debug on menu bar and then click Start Debugging
Press F5 key
Programming with Microsoft Visual Basic 2010, 5th Edition
Starting and Ending an Application (cont’d.)
18
Figure 1-23 Result of starting the splash screen application
Programming with Microsoft Visual Basic 2010, 5th Edition
The Code Editor Window
19
Event: User action such as double-clickingEvent procedure: Set of program
instructions that are processed when event occurs
Code Editor windowProvides templates for creating event
proceduresTo open Code Editor window
Right-click form and then click View Code
Programming with Microsoft Visual Basic 2010, 5th Edition
The Code Editor Window (cont’d.)
20
Figure 1-24 Code Editor window opened in the IDE
Programming with Microsoft Visual Basic 2010, 5th Edition
The Code Editor Window (cont’d.)
21
To collapse or expand a region of code in the Code Editor windowClick minus box to collapse codeClick plus box to expand code
Figure 1-25 Code collapsed in the Code Editor window
Programming with Microsoft Visual Basic 2010, 5th Edition
The Code Editor Window (cont’d.)
22
Class Name list boxLists names of objects included in UI
Method Name list boxLists appropriate events for selected object
To select a control’s event in code editor windowSelect class name first and then select
method nameSyntax
Rules of programming language
Programming with Microsoft Visual Basic 2010, 5th Edition
The Code Editor Window (cont’d.)
23
Procedure headerFirst line in code template for event
procedureProcedure footer
Last line in code template for event procedure
KeywordWord that has special meaning in
programming language Color-coded in IDE
Programming with Microsoft Visual Basic 2010, 5th Edition
The Code Editor Window (cont’d.)
24
Sub procedureBlock of code that performs a specific task
Keywords in a sub procedure blockSub: starts a sub procedurePrivate: restricts the use of the procedure to
the form where it appearsEnd Sub: indicates the end of a sub
procedureEvent sub procedure names include object
name and event nameExample: btnExit_Click
Programming with Microsoft Visual Basic 2010, 5th Edition
The Me.Close() Instruction
25
Method: Predefined procedure Can be called (or invoked) when needed
Me.Close() methodCauses current form to closeIf it is only form in application, the
application terminatesIntelliSense feature: Provides appropriate
selections as pop-up listsType first few letters of choiceThen use arrow keys to select an item in list
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
27
To add a control to a form, use tool from toolbox
Use Label control for text that user cannot editCan set properties of multiple controls
simultaneouslyTo start and stop an application in IDE, use the
Debug menu choiceUse Code Editor window to display object’s
event procedures Me.Close() method closes the current form at
run time
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