1.4. 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 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.

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


    Snaplines

    One of the most visible enhancements in Windows Forms 2.0 is the snaplines that are automatically shown when you drag and drop a control onto a form. Using snaplines, you can position controls on your form so that they are evenly spaced out. The figure shows snaplines in action when you try to position 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.




Visual Basic 2005 Jumpstart 2005
Visual Basic 2005 Jumpstart
ISBN: 059610071X
EAN: 2147483647
Year: 2005
Pages: 86
Authors: Wei-Meng Lee

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net