Microsoft Visual Basic 2010 Step by Step eBook

(Tina Meador) #1

394 Part III Designing the User Interface


System.Windows.Forms.Form class for its definition and default values. In fact, this class is
identified in the Properties window when you select a form in the Designer, as shown in
the following screen shot:

Although you haven’t realized it, you’ve been using inheritance all along to define the
Windows forms that you’ve been using to build Visual Basic applications. Although existing
forms can be inherited by using program code as well, the designers of Visual Studio
considered the task to be so important that they designed a special dialog box in the
development environment to facilitate the process. This dialog box is called the Inheritance
Picker, and it’s accessed through the Add New Item command on the Project menu. In the
following exercise, you’ll use the Inheritance Picker to create a second copy of a dialog box
in a project.

Inherit a simple dialog box


  1. Start Visual Studio, and create a new Visual Basic Windows Forms Application project
    named My Form Inheritance.

  2. Display the form in the project, and then use the Button control to add two button
    objects at the bottom of the form, positioned side by side.

  3. Change the Text properties of the Button1 and Button2 buttons to “OK” and “Cancel,”
    respectively.

  4. Double-click OK to display the Button1_Click event procedure in the Code Editor.

  5. Type the following program statement:


MsgBox("You clicked OK")


  1. Display the form again, double-click the Cancel button, and then type the following
    program statement in the Button2_Click event procedure:


MsgBox("You clicked Cancel")


  1. Display the form again, and set the Text property of the form to “Dialog Box .”


You now have a simple form that can be used as the basis of a dialog box in a program.
With some customization, you can use this basic form to process several tasks—you
just need to add the controls that are specific to your individual application.


  1. Click the Save All button to save your project, and then specify the C:\Vb10sbs\Chap16
    folder as the location.

Free download pdf