This documentation is archived and is not being maintained.

Button Constructor

Initializes a new instance of the Button class.

[Visual Basic]
Public Sub New()
[C#]
public Button();
[C++]
public: Button();
[JScript]
public function Button();

Remarks

By default the Button displays no caption. To specify the caption text, set the Text property.

Example

The following example creates a Button, sets its DialogResult property to DialogResult.OK, and adds it to a Form.

[Visual Basic] 
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 'InitializeMyButton

[C#] 
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);
 }
 

[C++] 
private:
    void InitializeMyButton() {
        // Create and initialize a Button.
        Button __gc *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);
    }; 

[JScript] 
private function InitializeMyButton()
 {
    // Create and initialize a Button.
    var button1 : Button = new Button();
 
    // Set the button to return a value of OK when clicked.
    button1.DialogResult = System.Windows.Forms.DialogResult.OK;
 
    // Add the button to the form.
    Controls.Add(button1);
 }
 

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

Button Class | Button Members | System.Windows.Forms Namespace | Button

Show: