Button.DialogResult Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets a value that is returned to the parent form when the button is clicked.
public:
virtual property System::Windows::Forms::DialogResult DialogResult { System::Windows::Forms::DialogResult get(); void set(System::Windows::Forms::DialogResult value); };
public virtual System.Windows.Forms.DialogResult DialogResult { get; set; }
member this.DialogResult : System.Windows.Forms.DialogResult with get, set
Public Overridable Property DialogResult As DialogResult
Property Value
One of the DialogResult values. The default value is None
.
Implements
Exceptions
The value assigned is not one of the DialogResult values.
Examples
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 );
}
private void InitializeMyButton()
{
// Create and initialize a Button.
Button button1 = 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);
}
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
Remarks
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
.
Applies to
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기