System.Windows.Forms.Form.DialogResult Property

Gets or sets the dialog result for the form.

Syntax

[System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
[System.ComponentModel.Browsable(false)]
public DialogResult DialogResult { set; get; }

Value

Documentation for this section has not yet been entered.

Remarks

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 System.Windows.Forms.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 Button.DialogResult property of a System.Windows.Forms.Button control on the form. When the user clicks the System.Windows.Forms.Button control, the value assigned to the Button.DialogResult property of the System.Windows.Forms.Button is assigned to the Form.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 Form.DialogResult property to be set to DialogResult.Cancel. The Form.Close method is not automatically called when the user clicks the Close button of a dialog box or sets the value of the Form.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 Control.Dispose(bool) 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 Form.DialogResult property when the user clicks the Close button by setting the Form.DialogResult property in an event handler for the Form.Closing event of the form.

Note:

If a System.Windows.Forms.Form is displayed as a modeless window, the value returned by the Form.DialogResult property might not return a value assigned to the form because the form's resources are automatically released when the form is closed.

Requirements

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0