Chapter 4 - Bobgill.com

advertisement
Clearly Visual Basic: Programming
with Visual Basic 2008
Chapter 4
I Need a Tour Guide
Objectives
• Create a Visual Basic 2008 Windows application
• Use the Label and PictureBox tools to add a control
to a form
• Set the properties of an object
• Save a solution
Clearly Visual Basic: Programming with Visual Basic 2008
2
Objectives (continued)
•
•
•
•
Size and align objects using the Format menu
Lock the controls on a form
Start and end an application
Close and open an existing solution
Clearly Visual Basic: Programming with Visual Basic 2008
3
OK, the Algorithm is Correct. What’s
Next?
• User interface
– What appears on the screen and with which you
interact while using a program
• Integrated development environment (IDE)
– Contains the tools and features you need to create,
run, and test your programs
Clearly Visual Basic: Programming with Visual Basic 2008
4
Clearly Visual Basic: Programming with Visual Basic 2008
5
Creating a Visual Basic Windows
Application
• Windows applications in Visual Basic
– Composed of solutions, projects, and files
• Solution
– Can contain several projects
• Project
– Container that stores files associated with project
Clearly Visual Basic: Programming with Visual Basic 2008
6
My Wizard Quick Start
Create a folder in C:\users\yourName\ called VB
Before you create your first application click on TOOLS- OPTIONS
Go to Projects and solutions
Visual Studio Project Locations: C:\users\you\VB
User Templates:
C:\users\you\VB
Item Templates:
C:\users\you\VB
Check the following:
Always show Error list Item in Solution Explorer
Track Active Item in Solution Explorer
Always show Solution
Save New Projects when created
Create a new VB Window Application
Name it My Wizard Project
Pin the Control Toolbar and Properties Window (Properties window is
Alphabetic)
Clearly
Basic:Text
Programming
with Visual
Basic 2008
7
Name
theVisual
Form1
property:
Wizard
Application
Clearly Visual Basic: Programming with Visual Basic 2008
8
Clearly Visual Basic: Programming with Visual Basic 2008
9
So Many Windows
• You will find it easier to work in the IDE if:
– You either close or auto-hide the windows you are not
currently using
• Auto Hide button
– Toggle button: clicking it once activates it; clicking it
again deactivates it
Clearly Visual Basic: Programming with Visual Basic 2008
10
Clearly Visual Basic: Programming with Visual Basic 2008
11
Creating the User Interface
• Windows Form Designer window
– Where you create (or design) your application’s user
interface
• Form
– The foundation for the user interface in a Windows
application
– Automatically includes a title bar that contains a
default caption
Clearly Visual Basic: Programming with Visual Basic 2008
12
Clearly Visual Basic: Programming with Visual Basic 2008
13
Creating the User Interface
(continued)
• Controls
– Objects added to a form
• Picture box
– Displays an image on a form
• Label controls
– Display text that user is not allowed to edit while
application is running
Clearly Visual Basic: Programming with Visual Basic 2008
14
Clearly Visual Basic: Programming with Visual Basic 2008
15
Save, Save, Save
• Good practice
– Save current solution every 10 or 15 minutes
• To save a solution
– Click on File on the menu bar, then click Save All
• Mini Quiz
1. A ____ control displays text that the user is NOT
allowed to edit while an application is running
2. The _________ contains the toos you use to
add objects to a form
3. GUI stands for _____________________
Clearly Visual Basic: Programming with Visual Basic 2008
16
Whose Property Is It?
• Properties
– Determine object’s appearance and behavior
• Name and current value of each property
– Appear in the Properties window when the object is
selected
• Select the Form
– Change the Text Property to Wizard Application
– Change StartPosition to Center Screen
– Change font to Segoe 9 Point
Clearly Visual Basic: Programming with Visual Basic 2008
17
Change the Properties Window to Alphabetical
Clearly Visual Basic: Programming with Visual Basic 2008
18
Whose Property Is It? (continued)
• Exercises
– Change the values assigned to some of the form’s
properties
– Change two properties of each label control
– Change two properties of each picture box
Clearly Visual Basic: Programming with Visual Basic 2008
19
Using the Format Menu
• Format menu
– Provides several options for manipulating controls in
the interface
• Exercises
– Make the PictureBox1 control the same size as the
PictureBox2 control
– Align the top borders of the two picture boxes
– Click the task box and Choose Image
find the images and import them to the screen
– Wizard 1 –Size Mode = Stretch
– Wizard 2- Size Mode = Auto Size
Clearly Visual Basic: Programming with Visual Basic 2008
20
Change Label1’s text property to Wizard 1 and Label2’s Text Property to Wizard 2
Change the Location property of Wizard 1 to 40,212
and the location property of Wizard 2 to 175, 212
Clearly Visual Basic: Programming with Visual Basic 2008
21
Lock Them Down
• Locking the controls
– Prevents them from being moved inadvertently as you
work in the IDE
• Unlock and then lock the controls
• Right Click the Form and Choose Lock Controls
Clearly Visual Basic: Programming with Visual Basic 2008
22
Clearly Visual Basic: Programming with Visual Basic 2008
23
OK, Let’s See the Interface in Action
• You can start an application by:
– Clicking Debug on the menu bar and then clicking
Start Debugging
or
– You can simply press the F5 key on your keyboard
Clearly Visual Basic: Programming with Visual Basic 2008
24
Clearly Visual Basic: Programming with Visual Basic 2008
25
Closing the Current Solution
• To close a solution
– Use the Close Solution option on the File menu
• When you close a solution
– All projects and files contained in the solution are also
closed
Clearly Visual Basic: Programming with Visual Basic 2008
26
Opening an Existing Solution
• To open an existing solution
– Use the File menu or the Start Page
• If a solution is already open in the IDE
– It is closed before another solution is opened
Clearly Visual Basic: Programming with Visual Basic 2008
27
Exiting Visual Studio
• To exit Visual Studio
– Use either the Close button on its title bar
or
– The Exit option on the File menu
Clearly Visual Basic: Programming with Visual Basic 2008
28
Summary
• Creating the user interface
– Fourth step in the problem-solving process
• Windows applications in Visual Basic
– Composed of solutions, projects, and files
• Label controls
– Display text that user is not allowed to edit while an
application is running
Clearly Visual Basic: Programming with Visual Basic 2008
29
Summary (continued)
• Picture boxes
– Used to display images on a form
• Good practice to save a solution every 10 or 15
minutes
• Form’s StartPosition property
– Specifies the position of the form when it first appears
on the screen
Clearly Visual Basic: Programming with Visual Basic 2008
30
Summary (continued)
• Font property
– Determines the type, style, and size of font used to
display text on the form
• Picture box control’s Image property
– Specifies name of file containing the image to display
• Good practice to:
– Lock the controls in place on the form
Clearly Visual Basic: Programming with Visual Basic 2008
31
Mini Quiz
1. The name of the image file assigned to a picture box control is stored in the
control’s __________ property
2. The value assigned to a label control’s ______ property appears in side the
Control
3. A control’s Location Property specifies the location of the control’s _________
corner on the form
4. How did you make the two picture boxes the same size?
5. To start a VB application, click Debug, and then click _________________
Actually the best way to start a VB program is to press the F5 KEY
REVIEW QUESTIONS
1. A Windows form automatically contains:
a. Close, Maximize, Minimize buttons b. a default caption c. a title bar
d. all of the above
2. To display the text “ABC Company” at the top of your interface, use a:
a. Form b. Label C. Picture Box D. None of theses
3. You use the ______ window to set characteristics of an object
a. Characteristics b. Designer c. Object d. Properties
4. The ______ property determines the position of a form when it is ran
a. StartPosition b. Location c. StartLocation d. InitialPosition
5. When aligning 2 objects, the first control selected is called the:
32
a. initializer b. Positioning c. reference d. none of the these
Page 73- #5 Program the Picture Box
Insert the Picture –
Lightning_bolts.gif
(downloaded earlier)
Double click on Each button to
Program them
The show button:
Picturebox1.visible = true
The Hide Button:
Picturebox1.visible = False
The Exit Button
Me.Close
SEE THE NEXT SLIDE
Clearly Visual Basic: Programming with Visual Basic 2008
33
Page 73-74 Project #5
Double click on each Button:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles Button1.Click
PictureBox1.Visible = True
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles Button2.Click
PictureBox1.Visible = False
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles Button3.Click
Me.Close()
End Sub
Clearly Visual Basic: Programming with Visual Basic 2008
34
Download