IButtonControl.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 the value returned to the parent form when the button is clicked.

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

Property DialogResult As DialogResult

Property Value

Type: System.Windows.Forms.DialogResult

One of the DialogResult values.

When a form is shown as a dialog box using the ShowDialog method and one of its buttons is clicked, the button's DialogResult value is assigned to the form's DialogResult property.

The following example inherits from the ButtonBase class and implements the IButtonControl interface. Implementation is added to the DialogResult property and the NotifyDefault and PerformClick methods.

Imports System
Imports System.Windows.Forms
Imports System.Drawing


Public Class MyButton
   Inherits ButtonBase
   Implements IButtonControl 
   Private myDialogResult As DialogResult

   Public Sub New()
      ' Make the button White and a Popup style
      ' so it can be distinguished on the form.
      Me.FlatStyle = FlatStyle.Popup
      Me.BackColor = Color.White
   End Sub

   ' Add implementation to the IButtonControl.DialogResult property.
   Public Property DialogResult() As DialogResult Implements IButtonControl.DialogResult
      Get
         Return Me.myDialogResult
      End Get

      Set
         If [Enum].IsDefined(GetType(DialogResult), value) Then
            Me.myDialogResult = value
         End If
      End Set
   End Property

   ' Add implementation to the IButtonControl.NotifyDefault method.
   Public Sub NotifyDefault(value As Boolean) Implements IButtonControl.NotifyDefault
      If Me.IsDefault <> value Then
         Me.IsDefault = value
      End If
   End Sub 

   ' Add implementation to the IButtonControl.PerformClick method.
   Public Sub PerformClick() Implements IButtonControl.PerformClick
      If Me.CanSelect Then
         Me.OnClick(EventArgs.Empty)
      End If
   End Sub

End Class

.NET Framework
Available since 1.1
Return to top
Show: