Export (0) Print
Expand All

Button.DialogResult Property

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)

'Declaration
Public Overridable Property DialogResult As DialogResult

Property Value

Type: System.Windows.Forms.DialogResult
One of the DialogResult values. The default value is None.

Implements

IButtonControl.DialogResult

ExceptionCondition
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 Sub InitializeMyButton()
    ' Create and initialize a Button. 
    Dim button1 As New 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)
End Sub 'InitializeMyButton

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft