Form.DialogResult Property
Gets or sets the dialog result for the form.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Property Value
Type: System.Windows.Forms.DialogResultA DialogResult that represents the result of the form when used as a dialog box.
| Exception | Condition |
|---|---|
| InvalidEnumArgumentException | The value specified is outside the range of valid values. |
The dialog result of a form is the value that is returned from the form when it is displayed as a modal dialog box. If the form is displayed as a dialog box, setting this property with a value from the DialogResult enumeration sets the value of the dialog box result for the form, hides the modal dialog box, and returns control to the calling form. This property is typically set by the DialogResult property of a Button control on the form. When the user clicks the Button control, the value assigned to the DialogResult property of the Button is assigned to the DialogResult property of the form.
When a form is displayed as a modal dialog box, clicking the Close button (the button with an X in the top-right corner of the form) causes the form to be hidden and the DialogResult property to be set to DialogResult.Cancel. The Close method is not automatically called when the user clicks the Close button of a dialog box or sets the value of the DialogResult property. Instead, the form is hidden and can be shown again without creating a new instance of the dialog box. Because of this behavior, you must call the Dispose method of the form when the form is no longer needed by your application.
You can use this property to determine how a dialog box is closed in order to properly process the actions performed in the dialog box.
Note |
|---|
You can override the value assigned to the DialogResult property when the user clicks the Close button by setting the DialogResult property in an event handler for the Closing event of the form. |
Note |
|---|
If a Form is displayed as a modeless window, the value returned by the DialogResult property might not return a value assigned to the form because the form's resources are automatically released when the form is closed. |
Available since 1.1
