Export (0) Print
Expand All

Button.Button Constructor

Initializes a new instance of the Button class.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public Button ()
public Button ()
public function Button ()
Not applicable.

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

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

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 void InitializeMyButton()
{
    // Create and initialize a Button.
    Button button1 = new Button();
    
    // Set the button to return a value of OK when clicked.
    button1.set_DialogResult(get_DialogResult().OK);
    
    // Add the button to the form.
    get_Controls().Add(button1);
} //InitializeMyButton

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);
 }
 

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft