O'Reilly logo

Visual Basic 2005 Jumpstart by Wei-Meng Lee

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Create an Exit Dialog Box

For most Windows applications, it is customary to ask users if they really want to quit an application when they either click the Close window button or select Exit on the File menu. In this section, you'll use Visual Studio 2005 and VB 2005 to add a dialog box that asks users to confirm that they really want to quit the application when they select either action.

  1. First, let's create the dialog box by adding a new Dialog to the project. You add a new Dialog to your project by right-clicking on the project name in Solution Explorer, which is WindowsApplication1, and then selecting Add New Item…. In the Add New Item dialog, select Dialog and use the default name of Dialog1.vb as shown in Figure 1-19.

    Adding a new Windows Form to the project

    Figure 1-19. Adding a new Windows Form to the project

  2. Notice that the Dialog window already comes with two buttons: OK (OK_Button) and Cancel (Cancel_Button).

  3. Populate the dialog with the Label control shown in Figure 1-20 by dragging and dropping it from the Toolbox. Also, resize the dialog window.

    Populating the dialog window with the Label control

    Figure 1-20. Populating the dialog window with the Label control

  4. Set the properties of the various controls to the values shown in Table 1-1. To set the properties of a control, right-click the control and select Properties to display its Property window. Look for each Property you wish to set by scrolling through the Properties window and entering the appropriate value.

    Table 1-1. Properties of the various controls

    Control

    Property

    Value

    Comments

    Dialog1

    Text

    Exit

    Changes the title of the Windows Form

    Dialog1

    AcceptButton

    OK_Button

    Sets the OK button to the default button of the form so that it is clicked when the user presses the Enter key.

    Note that this has already been set for you by Visual Studio 2005.

    Dialog1

    CancelButton

    Cancel_Button

    Sets the Cancel button to be activated when the user presses the Esc key.

    Note that this has already been set for you by Visual Studio 2005.

    OK_Button

    DialogResult

    OK

    Sets the OK button to the value of OK for the dialog result.

    Cancel_Button

    DialogResult

    Cancel

    Sets the Cancel button to the value of Cancel for the dialog result.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required