Home

Characteristics of Dialog Boxes

 

The Border Style of a Dialog Box

There are a few actions you should perform on a form to transform it into a dialog box; but normally, these are only suggestions, not rules. Based on the Microsoft Windows design and standards, to create a dialog box, you should set a formís FormBorderStyle property to FixedDialog. Setting this property changes the borders of the form to the standard borders of a dialog box (the border of a dialog box is thinner than that of a regular form). You can set this characteristic in the Properties window or programmatically.

Here is an example:

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

    FormBorderStyle = FormBorderStyle.FixedDialog;
}

The Minimize and Maximize Boxes

Besides taking care of the border, you should also set both the MinimizeBox and the MaximizeBox properties to False. This causes the window to display only the system Close button. You can set these characteristics in the Properties window or programmatically. Here is an example:

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

        FormBorderStyle = FormBorderStyle.FixedDialog;
        MinimizeBox = false;
        MaximizeBox = false;
}

This would produce:

Form

Practical LearningPractical Learning: Configuring a Dialog Box

  1. To transform the PropertyEditor form into a dialog box, in the Properties window, change its characteristics as follows:
    FormBorderStyle: FixedDialog
    StartPosition:        CenterParent
    MinimizeBox:         False
    MaximizeBox:        False
    ShowInTaskbar:    False
  2. Design the dialog box as follows:
     
    Solas Property Rental
    Control Text Name
    Label Property Type:  
    TextBox   txtPropertyType
    Button Cancel btnCancel
    Label Bedrooms:  
    TextBox   txtBedrooms
    Button OK btnOK
    Label Bathrooms:  
    TextBox   txtBatrooms
    Label Monthly Rent:  
    TextBox   txtMonthlyRent

Closing a Dialog Box

You should provide a way for the user to close the dialog box. A dialog box should have at least one button labeled OK. This button allows the user to acknowledge the message of the dialog box and close it by clicking the button. If the user press Enter, the dialog box should also be closed as if the OK button was clicked.

Accepting an Action

Often the user will be presented with various options on a dialog box and may be asked to make a decision on the available controls. Most of the time, if you are creating such a dialog box, besides the OK button, it should also have a Cancel button. The OK button should be the default so that if the user presses Enter, the dialog box would be closed as if the user had clicked OK. Clicking OK or pressing Enter would indicate that, if the user had made changes on the controls of the dialog box, those changes would be acknowledged and kept when the dialog box is closed and usually the changed values of the control would be transferred to another dialog box or form. Keep in mind that you are responsible for implementing this functionality.

To fulfill this functionality of the OK button, after adding it to a dialog box (or form), open the AcceptButton combo box in the Properties window for the form and select the name of the button.

Practical LearningPractical Learning: Accepting an Action

  1. Click an unoccupied area of the form
  2. In the Properties window, click the arrow of the AcceptButton field and select btnOK

Cancelling an Action

The Cancel button is used to allow the user to dismiss whatever changes would have been made on the controls of the dialog box. The dialog box should also be configured so that if the user presses Esc, the dialog box would be closed as if the user had clicked Cancel.

To fulfill this functionality of the Cancel button, after adding it to a dialog box (or form), open the CancelButton combo box in the Properties window for the form and select the name of the button.

Besides the OK and the Cancel buttons, a dialog box can be created with additional buttons such as Finish or Help, etc. It depends on its role and the decision is made by the application developer.

Practical LearningPractical Learning: Cancelling an Action

  1. In the Properties window, click the arrow of the CancelButton field and select btnCancel
     
    Solas Property Rental
  2. Display the first form

The Help Button

Besides the system Close button, if you are planning to provide help on a dialog box, you can equip it with a Help button. To support this, the Form class is equipped with a Boolean property named HelpButton. The default value of this property is false. In the Properties window, you can set it to True. If you are programmatically creating the dialog box, you can access this property and set its value to true. Here is an example:

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

        FormBorderStyle = FormBorderStyle.FixedDialog;
        MinimizeBox = false;
        MaximizeBox = false;

        HelpButton = true;
}

This would produce:

Form

When the user clicks the help button, the mouse cursor becomes equipped with a question mark. Here is an example:

Form

You can then write code so that, when the user clicks a control on the dialog box, some guiding help is provided as a tool tip.

 

Previous Copyright © 2007 FunctionX, Inc. Next