Microsoft Visual Basic 2010 Step by Step eBook

(Tina Meador) #1

Chapter 14 Managing Windows Forms and Controls at Run Time 367


Visual Basic displays the second form. This form contains the label and button objects
that you defined by using program code. The label object contains the current date, as
shown here:


  1. Click the Cancel button to close the new form.

  2. Click the Display Date button again.


The new form opens as it did the first time.


  1. Press ESC to close the form.


Because you set the CancelButton property to the btnCancel object, clicking Cancel
and pressing ESC produce the same result.


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


The program stops, and the development environment returns.

Organizing Controls on a Form


When you add controls to a form programmatically, it takes a bit of trial and error to
position the new objects so that they’re aligned properly and look nice. After all, you don’t
have the Visual Studio Designer to help you—just the (x, y) coordinates of the Location
and Size properties, which are clumsy values to work with unless you have a knack for
Free download pdf