DialogResult

While many dialog boxes have the ControlBox, MaximizeBox, MinimizeBox, and ShowInTaskBar properties set to false, the previous example left ControlBox set to the default value of true. The Control box allows the user to close the dialog by clicking on the X in the upper-righthand corner. If the ControlBox is suppressed in a modal dialog box that has no other controls that close the form, then there is no obvious way for the user to close the dialog or end the application, short of killing the application in Task Manager. (The user can press Alt+F4 to close any form or dialog box, or press Escape to close a modal dialog. The developer can always stop debugging.)

Dialog boxes typically have one or more buttons for accepting the user's interaction and/or terminating itself. These buttons will often be assigned the purpose of causing the dialog box to send a standard message, such as OK, Cancel, Yes, or No. At other times, there may be a custom Text property on the button, such as Update Database. In any case, the Click event for the button can be handled, code can be executed, and a result can be sent to the parent form.

A property of every modal form or dialog called DialogResult allows you to set or retrieve a return value when it is closed. The property can be set programmatically at runtime. The valid values of the DialogResult property are members of the DialogResult enumeration, detailed in Table 6-4. The value is set programmatically, typically by a button control ...

Get Programming .NET Windows Applications now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.