Button.DialogResult 屬性

定義

取得或設定當按鈕按下時傳回父表單的值。

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 值。 預設值是 None

實作

例外狀況

所指派的值不是其中一個 DialogResult 值。

範例

下列程式碼範例會 Button 建立 、將其 DialogResult 屬性設定為 OK ,並將它新增至 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 方法顯示,請按一下按鈕會關閉父表單,而不需要連結任何事件。 然後,當按一下按鈕時,表單 DialogResult 的 屬性會設定為 DialogResult 按鈕的 。

例如,若要建立 [是/否/取消] 對話方塊,只要新增三個按鈕,並將其 DialogResult 屬性設定為 YesNoCancel

適用於