Picture an application comprised of several forms, where one form calls another, which may call yet another. Many MDI applications work this way. Generally speaking, you may keep all the forms open, moving among them as much as you'd like. This is called modeless behavior.
In contrast, consider the behavior of most dialog boxes in most applications. A user action causes a dialog box to be displayed, generally for the purpose of presenting information to or gathering input from the user. In the first case, the program cannot proceed until it knows that the information was presented to and acknowledged by the user. In the latter case, the program cannot proceed until either the requisite input has been gathered from the user or the user cancels the dialog. In either case, the program cannot proceed until the user has dismissed the dialog box. This is known as modal behavior.
Not all dialog boxes are modal. Common examples of modeless dialog boxes are those found in many word processors and text editors for finding text. As you search for text, the dialog box remains open and you can move freely between the dialog box and the document it is searching.
|
Both forms and dialog boxes can be either modal or modeless, depending on how you invoke them. To make them modeless, call Show( ); to make them modal, call ShowDialog( ).
The following lines of code open a modal dialog:
Form frm = new Form( ); frm.ShowDialog( );
By changing the method call to Show (rather than ShowDialog), you invoke the same form, but modeless:
Form frm = new Form( ); frm.Show ( );
Good UI design suggests that you should use modal dialogs only when absolutely necessary.
Windows Forms and the .NET Framework
Getting Started
Visual Studio .NET
Events
Windows Forms
Dialog Boxes
Controls: The Base Class
Mouse Interaction
Text and Fonts
Drawing and GDI+
Labels and Buttons
Text Controls
Other Basic Controls
TreeView and ListView
List Controls
Date and Time Controls
Custom Controls
Menus and Bars
ADO.NET
Updating ADO.NET
Exceptions and Debugging
Configuration and Deployment