Microsoft Visual Basic 2010 Step by Step eBook

(Tina Meador) #1

362 Part III Designing the User Interface



  1. Click the Close button on the form to close the program.


You’ve experimented with a few basic StartPosition settings for positioning a form at run
time. Now you’ll use the DesktopBounds property to size and position a second form window
while the program is running. You’ll also learn how to create a new form at run time without
using the Add Windows Form command on the Project menu.

Set the DesktopBounds property


  1. Use the Button control to add a button object to the form, and then change the Text
    property of the button object to “Create Form .”

  2. Double-click the Create Form button to display the Button1_Click event procedure in
    the Code Editor.

  3. Type the following program code:


'Create a second form named form2
Dim form2 As New Form

'Define the Text property and border style of the form
form2.Text = "My New Form"
form2.FormBorderStyle = FormBorderStyle.FixedDialog

'Specify that the position of the form will be set manually
form2.StartPosition = FormStartPosition.Manual

'Declare a Rectangle structure to hold the form dimensions
'Upper left corner of form (200, 100)
'Width and height of form (300, 250)
Dim Form2Rect As New Rectangle(200, 100, 300, 250)

'Set the bounds of the form using the Rectangle object
form2.DesktopBounds = Form2Rect
Free download pdf