Pages

Friday 10 August 2012

Difference between Form.Show() vs Form.ShowDialog().


Forms and dialog boxes are either modal or modeless.

modal form or dialog box must be closed or hidden before you can continue working with the rest of the application.

A Modeless forms let you shift the focus between the form and another form without having to close the initial form. The user can continue to work elsewhere in any application while the form is displayed.

Modeless forms are harder to program, because users can access them in an unpredictable order. You have to keep the state of the application consistent no matter what the user does. Often, tool windows are shown in a modeless fashion.

Form.Show()
Form.ShowDialog()
It opens dialog box in modeless format.
It opens dialog box in modally format.
Ex:If we have two form like Form1 and Form2. If we open Form2 from Form1 than both form are remain active.
Ex:If we have two form like Form1 and Form2. If we open Form2 from Form1 than only Form2 remain active, we can't change/operate Form1 till Form2 closed.
If a form is shown as modeless, the code following the Show method is executed immediately after the form is displayed.
If a form is displayed as modal, the code following the ShowDialog method is not executed until the dialog box is closed.

No comments:

Post a Comment