Button::DialogResult Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets or sets a value that is returned to the parent form when the button is clicked.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public:
property DialogResult DialogResult {
	virtual DialogResult get();
	virtual void set(DialogResult value);
}

Property Value

Type: System.Windows.Forms::DialogResult

One of the DialogResult values. The default value is None.

Exception Condition
InvalidEnumArgumentException

The value assigned is not one of the DialogResult values.

If the DialogResult for 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 your 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 box, simply add three buttons and set their DialogResult properties to Yes, No, and Cancel.

The following code example creates a Button, sets its DialogResult property to OK, and adds it to a Form.

private:
   void InitializeMyButton()
   {
      // Create and initialize a Button.
      Button^ button1 = gcnew Button;

      // Set the button to return a value of OK when clicked.
      button1->DialogResult = ::DialogResult::OK;

      // Add the button to the form.
      Controls->Add( button1 );
   }

.NET Framework
Available since 1.1
Return to top
Show: