Dialog Boxes



A dialog box is a form defined with particular properties. Like a form, a dialog box is referred to as a container. Like a form, a dialog box is mostly used to host child controls, insuring the role of dialog between the user and the machine. Here is an example of a dialog box:



A dialog box has the following characteristics:

  • The only system button it is equipped with is Close System Close. As the only system button, this button allows the user to dismiss the dialog and ignore whatever the user would have done on the dialog box
  • It cannot be minimized, maximized, or restored. A dialog box does not have any other system button but Close
  • It is usually modal, in which case the user is not allowed to continue any other operation on the same application until the dialog box is dismissed
  • It provides a way for the user to close or dismiss it

Practical LearningPractical Learning: Introducing Dialog Boxes

  1. Start Microsoft Visual Basic and create a new Windows Application named SolasPropertyRental1
  2. From the Common Controls section of the Toolbox, click ListView and click the form
  3. While the list view is still selected, in the Properties window, change the following characteristics
    (Name): lvwProperties
    View: Details
  4. Still in the Properties window, click Columns and click its ellipsis button
  5. In the ColumnHeader Collection Editor, click Add
  6. In the right list, click Text and type Property #
  7. Click Add.
    In the right list, click Text and type Property Type
  8. Click Add.
    In the right list, click Text and type Bedrooms
  9. Click Add.
    In the right list, click Text and type Bathrooms
  10. Click Add.
    In the right list, click Text and type Monthly Rent
  11. Click OK
  12. Complete the design of the form as follows:
    Solas Property Rental
    Control Text Name
    Button New Property... btnNewProperty
    Button Close btnClose
  13. To add another form to the project, on the main menu, click Project -> Add Windows Form...
  14. In the Templates list, make sure Windows Form is selected.
    Set the Name to PropertyEditor and click Add

Dialog Box Creation

To create a dialog box, you start with a form, which you can get by creating a Windows Application or deriving a class from Form. Here is an example:

Imports System.Drawing
Imports System.Windows.Forms

Module Exercise

    Public Class Starter
        Inherits Form

        Dim components As System.ComponentModel.Container

        Public Sub New()
        End Sub

        Public Sub InitializeComponent()
            Text = "Domain Configuration"
            Width = 320
            Height = 150
            Location = New Point(140, 100)
            StartPosition = FormStartPosition.CenterScreen
        End Sub

    End Class

    Function Main() As Integer

        Dim frmStart As Starter = New Starter


        Return 0
    End Function

End Module

This would produce:

Starting a dialog box


Previous Copyright © 2007-2008 FunctionX, Inc. Next