Button 建構函式

定義

初始化 Button 類別的新執行個體。

public:
 Button();
public Button ();
Public Sub New ()

範例

下列程式碼範例會 Button 建立 、將其 DialogResult 屬性設定為 OK 的值 DialogResult ,並將它新增至 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

備註

根據預設, Button 不會顯示任何標題。 若要指定標題文字,請設定 Text 屬性。

適用於

另請參閱