Home

Dialog Boxes

 

Description

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:

The Run 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 C# 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
    ListView    
    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:

using System;
using System.Drawing;
using System.Windows.Forms;

public class Exercise : System.Windows.Forms.Form
{
    public Exercise()
    {
        InitializeComponent();
    }

    private void InitializeComponent()
    {
        Text = "Domain Configuration";
        Width = 320;
        Height = 150;
        Location = new Point(140, 100);
        StartPosition = FormStartPosition.CenterScreen;
    }
}

public class Program
{
    static int Main()
    {
        System.Windows.Forms.Application.Run(new Exercise());
        return 0;
    }
}

This would produce:

Starting a dialog box

 

Home Copyright © 2007-2012 FunctionX Next