Gets or sets a value that is returned to the parent form when the button is clicked.
[Visual Basic] Overridable Public Property DialogResult As DialogResult [C#] public DialogResult DialogResult {virtual get; virtual set;} [C++] public: __property virtual DialogResult get_DialogResult(); public: __property virtual void set_DialogResult(DialogResult); [JScript] public function get DialogResult() : DialogResult; public function set DialogResult(DialogResult);
One of the DialogResult values. The default value is None.
Exception Type | Condition |
---|---|
InvalidEnumArgumentException | The value assigned is not one of the DialogResult values. |
If the value of this property is set to anything other than None, and if the parent form was displayed through the ShowDialog method, clicking the button closes the parent form without you having to hook up any events. The form's DialogResult property is then set to the DialogResult of the button when the button is clicked.
For example, to create a "Yes/No/Cancel" dialog, simply add three buttons and set their DialogResult properties to Yes, No, and Cancel.
The following example instantiates a Button and sets its DialogResult property to DialogResult.Ok.
[Visual Basic]
' Instantiate a Button. Private Button1 As System.WinForms.Button Private MySub() ' Initialize a new Button. Form1.Button1 = New System.WinForms.Button ' Set the button to return a value of Ok when clicked. Button1.DialogResult = DialogResult.Ok ' Add the button to the form. Form1.Controls.Add(Button1) End Sub