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 framed window 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. Here is an example:
After creating a dialog used as an addition to an existing form or an existing dialog box, to call it as modal, use the ShowDialog() method.
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. A modeless dialog box has the following characteristics
Here is an example:
Since the modeless dialog box does not display its button on the task bar, the user should 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. After creating the dialog box, to display it as modeless, call the Show() method. The fundamental difference between the ShowDialog() and the Show() methods is that the former displays a modal dialog box, which makes sure that the called dialog box cannot go in the background of the main application. By contrast, the Show() method only calls the dialog box every time it is requested. For this reason, it is up to you to make sure that the modeless dialog box always remains on top of the application. This is easily taken care of by setting the Boolean TopMost property of the form to True. There are two main ways a normal modeless dialog box can be dismissed:
When you create a Windows Forms Application, the starting form is made available to you. If one form is not enough for your application, you can add as many as necessary. To add (or to create) a (new) form, you have various options:
In the Add New Item dialog box and in the Templates section, click Window Form (.NET), provide a name in the Name edit box then click Open. If your application is using various forms and you want to display a particular one at design time:
If you visually add two (or more) forms to your application, you may need to link them, allow one to call the other. To do this, in the top section of the file, type #include followed by the name of the header file in which the form was defined. In the section where you want to access the form, declare a handle to the class of the form and use the new operator to allocate memory for it. To display the other form, you can call its Show() method.
|
|
||
Previous | Copyright © 2007-2013, FunctionX | Home |
|