Overview of Dialogs

Dialogs are short-lived windows that communicate with the user and receive input. If the user interacts with the dialog, the input is used to perform some action in the application. In Windows Forms, a dialog is constructed much the same way as a normal window. However, dialogs differ in behavior and are launched by calling the ShowDialog method of a Form derived type, rather than the Show method.

Dialogs come in two types, modal and modeless. Modal dialogs force the user to acknowledge the dialog before moving on to the application. Perhaps the most familiar modal dialog is the MessageBox.

Modeless dialogs enable the user to interact with both the dialog and the application interchangeably. A good example of the modeless dialog is the Find dialog. For simplicity, I won't start off with a dialog as sophisticated as a Find dialog. Instead, the first example in this section simply demonstrates the behavior of both modal and modeless dialogs (see Listing 7.1).

Listing 7.1 Showing Forms as Dialogs (ModalModeless.cs)
 private void btnModal_Click(object sender, System.EventArgs e) {    ModalDialog modal = new ModalDialog();    modal.ShowDialog(); } private void btnModeless_Click(object sender, System.EventArgs e) {    ModelessDialog modeless = new ModelessDialog();    modeless.Show(); } 

As shown in the btnModal_Click method in Listing 7.1, the ShowDialog method makes a Windows Form display as modal. The code examples for this book include logic for displaying both a modal and modeless dialog in the same application. You can test the behavior by launching each dialog type and trying to click the title bar of the main form. The modeless dialog will allow the main form to be selected, but the modal dialog will not.



C# Builder KickStart
C# Builder KickStart
ISBN: 672325896
EAN: N/A
Year: 2003
Pages: 165

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net