de#4 #&Uhdwlqj#D#6Lpsoh#$Ssolfdwlrq: 2emhfwlyhv
de#4 #&Uhdwlqj#D#6Lpsoh#$Ssolfdwlrq: 2emhfwlyhv
/DE#4=#&UHDWLQJ#D#6LPSOH#$SSOLFDWLRQ
In this lab, you will learn how to create a simple application in Microsoft® Visual Basic®. Subsequent labs
in this course will explore each of the tasks you try here in more detail.
2EMHFWLYHV
After completing this lab, you will be able to:
To complete the exercises in this lab, you must have the required software. For detailed information about
the labs and setup for the labs, see Labs in this course.
The solution for this lab is located in the <install folder>\Labs\Lab01\Solution folder.
3UHUHTXLVLWHV
There are no prerequisites for this lab.
([HUFLVHV
The following exercises provide practice working with the concepts and techniques covered in Chapter 1.
([HUFLVH#4=#8VLQJ#&RQWUROV
In this exercise, you will practice placing controls on a form to become more familiar with the Visual Basic
development environment and controls.
([HUFLVH#5=#&UHDWLQJ#DQ#$SSOLFDWLRQ#ZLWK#&RGH
In this exercise, you will create an application that changes properties of controls while the application is
running.
([HUFLVH#6=#8VLQJ#&RGH#IURP#WKH#+HOS#)LOH
In this exercise, you will locate a code sample in MSDN™ Help and copy it into an application.
Lab 1: Creating a Simple Application
31 ([HUFLVH#4=#8VLQJ#&RQWUROV
In this exercise, you will practice placing controls on a form to become more familiar with the Visual Basic
development environment and controls.
Notes
Page 2
Lab 1: Creating a Simple Application
Notes
Page 3
Lab 1: Creating a Simple Application
31 ([HUFLVH#5=#&UHDWLQJ#DQ#$SSOLFDWLRQ#ZLWK#&RGH
In this exercise, you will use the same project used in Exercise 1 and create an application that changes
properties of controls while the application is running.
X Add a TextBox and a Label control to the form and align them horizontally
… 1. Add a TextBox control to the form.
… 2. Add a Label control to the form, and position the Label to the right side of the TextBox.
… 3. Click on the form and drag a box around both controls to select them.
… 4. Click the control on the form that you want the other controls to align to.
The control's grab handles should change to a solid color.
… 5. On the Format menu, click Align, and then click Tops to horizontally align the controls to the last
selected control.
This code statement changes the caption of the Label control to the text the user types in the TextBox
control.
… 3. Run the application and type some text in the text box. Note what happens.
… 4. Close the application and return to Design mode.
Notes
Page 4
Lab 1: Creating a Simple Application
Notes
Page 5
Lab 1: Creating a Simple Application
31 ([HUFLVH#6=#8VLQJ#&RGH#IURP#WKH#+HOS#)LOH
In this exercise, you will locate a code sample in MSDN Help and copy it into an application.
X Open Project1
… 1. Start Visual Basic.
… 2. Click the Recent tab, select Project1, and then click Open.
… 3. If the form is not visible, select it in the Project Explorer window and click View Object.
End Sub
… 2. In the Code Editor window, select MouseMove from the Procedure drop-down list box.
The contents of the Code Editor window will change to the following:
Private Sub Form_MouseMove(Button As Integer, Shift As _
Integer, X As Single, Y As Single)
End Sub
X Copy example code from MSDN Help and paste it into a Visual Basic application
… 1. Click the Example jump topic at the top of the Help window.
A Help window should open with an example of how to use the FillColor property.
… 2. Select the three lines of code between the Sub and End Sub statements.
… 3. Right-click anywhere on the selected text and click Copy to copy the selected lines to the Clipboard.
… 4. Close the MSDN Help window.
You should now be back in the Code Editor window, displaying the Form_MouseMove event
procedure. If not, in the Code Editor window, click Form on the Object list and MouseMove from the
Procedure list to move to the Form_MouseMove event procedure.
… 5. Highlight the FillColor command in the procedure.
Notes
Page 6
Lab 1: Creating a Simple Application
… 6. On the Edit menu, click Paste to paste the copied code into the Form_MouseMove event procedure.
The resulting event procedure should look similar to this:
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
' Choose random FillColor
FillColor = QBColor(Int(Rnd * 15))
' Choose random FillStyle
FillStyle = Int(Rnd * 8)
' Draw a circle
Circle (X, Y), 250
End Sub
Notes
Page 7
This page intentionally left blank.