Professional Documents
Culture Documents
Chapter 22
Chapter 22
Topics :
2.1 Focus on Problem Solving: Building the Directions Application.
2.2 Focus on Problem Solving: Responding to Events
2.3 Modifying a Control’s Text Property with Code
2.4 The AutoSize, BorderStyle, and TextAlign Properties
2.5 Displaying User Messages
2.6 Clickable Images
2.7 Using Visual Studio Help
2.8 Debugging Your Application
2.1 Focus on Problem Solving:
Building the Directions Application
1. Clearly define what the application is to do.
Purpose: Display a map to the Highlander Hotel
Input: None
Process: Display a form
Output: Display on the form a graphic image showing a map
2. Visualize the application running
on the computer and design its user interface.
3. Determine the controls needed.
4.Define the values of each control’s relevant properties.
5. Start Visual Studio and create the forms and other controls
Beginning the Directions application
Properties window showing Form1
Changing the Label’s font size and style
Font property in the Properties window
Adding a Label control to the Directions application
The PictureBox Control
has several properties, but the following two properties are of particular
interest:
• The Image property specifies the image file that is to be displayed by the
control.
• The SizeMode property specifies how the image is to be displayed. It can be
set to one of the following values:
• Normal
• StretchImage
• AutoSize
• CenterImage
• Zoom
Visual Studio modes: Design Mode, Run Mode, and
Break Mode
• Design Mode: this is the mode in which you create an application.
• Run mode: The application will be running on the computer, and you can
interact with it as the user.
There are three ways to run an application from the Visual Studio
environment:
• Click the Start Debugging button ( ) on the toolbar
• Click DEBUG on the menu bar, then select Start Debugging
• Press the F5 key
• Break mode is a special mode that allows you to momentarily suspend a
running application for testing and debugging purposes. It is also the mode that
Visual Studio enters when a running application encounters a runtime error.
2.2 Focus on Problem Solving: Responding to Events
such as mouse clicks and keyboard input.
Adding a Label control for the written directions
Adding button and coding:
2.3 Modifying a Control’s Text Property with Code
lblDirections.Visible = True
lblMessage.Text = "Programming is fun!
code
Public Class Form1
Private Sub btnExit_Click(...) Handles btnExit.Click
' End the application.
Me.Close()
End Sub
Private Sub btnFeet_Click(...) Handles btnFeet.Click
' Display the conversion to feet.
lblMessage.Text = "1 Kilometer = 3,281 feet"
End Sub
Private Sub btnInches_Click(...) Handles btnInches.Click
' Display the conversion to inches.
lblMessage.Text = "1 Kilometer = 39,370 inches"
End Sub
Private Sub btnMiles_Click(...) Handles btnMiles.Click
' Display the conversion to miles.
lblMessage.Text = "1 Kilometer = 0.6214 miles"
End Sub
Private Sub btnYards_Click(...) Handles btnYards.Click
' Display the conversion to yards.
lblMessage.Text = "1 Kilometer = 1,093.6 yards"
End Sub
End Class
2.4 The AutoSize, BorderStyle, and TextAlign Properties
- The AutoSize property is a Boolean property that is set to True by default.
- The Label control’s BorderStyle property may have one of three values:
None, FixedSingle, and Fixed3D. The property is set to None by default.
- By default, a label’s text is aligned with the top and left edges of the label’s
bounding box.
Changing a Label’s TextAlign Property with Code
HELP on the Visual Studio menu bar, and then selecting View Help. (Or,
you can simply press Ctrl+F1.)
This opens the MSDN Library in your Web browser.
2.8 Debugging Your Application
At some point, most applications contain bugs (errors) that prevent the
application from operating properly. In this section, you learn
fundamental debugging techniques.
Visual Basic reports errors in your project as soon as it finds them.
In general, there are two types of errors: compile errors and runtime
errors.