Button.DialogResult Свойство
Определение
Возвращает или задает значение, возвращаемое в родительскую форму при нажатии кнопки.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
Значение свойства
Одно из значений перечисления DialogResult.One of the DialogResult values. Значение по умолчанию — None
.The default value is None
.
Реализации
Исключения
Назначенное значение не является одном из значений DialogResult.The value assigned is not one of the DialogResult values.
Примеры
Следующий пример кода создает Button , присваивает его DialogResult свойству значение OK
и добавляет его в Form .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
Комментарии
Если DialogResult для этого свойства задано значение, отличное от None
, и если родительская форма была отображена с помощью ShowDialog метода, то нажатие кнопки закрывает родительскую форму без необходимости подключения каких-либо событий.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. После нажатия DialogResult кнопки в свойстве формы устанавливается значение для DialogResult кнопки.The form's DialogResult property is then set to the DialogResult of the button when the button is clicked.
Например, чтобы создать диалоговое окно «да/нет/Отмена», просто добавьте три кнопки и задайте для них DialogResult свойства Yes
, No
и Cancel
.For example, to create a "Yes/No/Cancel" dialog box, simply add three buttons and set their DialogResult properties to Yes
, No
, and Cancel
.