Button 构造函数

定义

初始化 Button 类的新实例。

C#
public Button ();

示例

下面的代码示例创建一个 Button,将其 DialogResult 属性设置为 OKDialogResult,并将其添加到 a Form

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

注解

默认情况下, Button 不显示标题。 若要指定标题文本,请设置 Text 属性。

适用于

产品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Windows Desktop 3.0, 3.1, 5, 6, 7

另请参阅