Dialog Boxes

 

Regular Dialog Boxes

 

Introduction

A dialog box is a form with particular properties. Like a form, a dialog box is referred to as a container. It is the primary interface of user interaction with the computer. By itself, a dialog box means nothing. The controls it hosts accomplish the role of dialog between the user and the machine. Here is an example of a dialog box:

Example of a dialog box

A dialog box has the following characteristics:

  • It is equipped with the system Close button . 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 the dialog. Most dialog boxes have an OK and a Cancel buttons, although this depends on the application developer.
    When the dialog has the OK and the Cancel buttons, the OK button is configured to behave as if the user had pressed Enter. In that case, whatever the user had done would be acknowledged and transferred to the hosting dialog box, window, or application. Pressing Esc applies the same behavior as if the user had clicked Cancel.

 

Dialog Box Creation

There are two main actions you can perform on a form to qualify it as 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 to true prevents the dialog box from being resized at run time, which respects one of the rules of a dialog box.

  • Set the MaximizeBox property to False to remove the Maximize buttons

  • Set MinimizeBox property to False to remove the system Minimize button
    When both the MaximizeBox and the MinimizeBox properties are set to False, the system Maximize and Minimize buttons are removed from the dialog box

  • You should/must 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. To fulfill this requirement, from the Toolbox, you can click the Button control and click the dialog box.

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. The changed values of the control would be transferred to another dialog box or form.

To fulfill this rule for the OK button, after adding the button(s), click the form to select it. Then, click its AcceptButton field in the Properties window. This reveals its combo box. Click its arrow and select the name of the button whose action would be performed when the user presses Enter.

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 rule for the Cancel button, after adding the buttons, click the form to select it. Then, in the Properties window, click its CancelButton field to display its combo box. Click the arrow of the CancelButton combo box and select the name of the button whose action would be performed when the user presses Esc. Make sure sure the button selected for the AcceptButton property is not the same as the one selected for the CancelButton property.

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.

Modal and Modeless Dialog Boxes

 

Modal Dialog Boxes

There are two types of dialog boxes: modal and modeless. A Modal dialog box is one that the user must first close in order to have access to any other form or dialog box of the same application.

One of the scenarios in which you use a dialog box is to create an application that is centered around one. In this case, if either there is no other form or dialog box in your application or all the other forms or dialog boxes depend on this central dialog box, it must be created as modal. Such an application is referred to as dialog-based.

Some applications require various dialog boxes to complete their functionality. When in case, you may need to call one dialog box from another and display it as modal.

The Date and Time dialog box of WordPad is an example of a modal dialog box: if opened, the user must close it in order to continue using WordPad. A modal dialog box

After creating a form and configuring it as a dialog box, to call it as modal, use the ShowDialog() method. 

Modeless Dialog Boxes

A dialog box is referred to as modeless if the user does not have to close it in order to continue using the application that owns the dialog box:

The Find dialog box of WordPad (also the Find dialog box of most applications) is an example of a modeless dialog box. If it is opened, the user doesn't have to close in order to use the application or the document in the background. A modeless dialog box

A modeless dialog box should/must not display its button on the task bar. The user should still know that the dialog box is opened. To make the presence of a modeless dialog box obvious to the user, it typically displays on top of its host application until the user closes it.

A modeless dialog box is created from a form but it should look like a regular dialog box or a tool window. Therefore, to create a modeless dialog box, set the FormBorderStyle property to an appropriate value such as FixedSingle, FixedToolWindow, Sizable or SizableToolWindow. Also, set its ShowInTaskbar property to False.

 

Previous Copyright © 2003-2015, FunctionX