请单击以进行评分并提供反馈
MSDN
MSDN Library
.NET 开发
先前版本
Button 类

  开启低带宽视图
此页面仅适用于
Microsoft Visual Studio 2005/.NET Framework 2.0

同时提供下列产品的其他版本:
.NET Framework 类库
Button 类

表示 Windows 按钮控件。

命名空间:System.Windows.Forms
程序集:System.Windows.Forms(在 system.windows.forms.dll 中)

Visual Basic(声明)
<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
Public Class Button
    Inherits ButtonBase
    Implements IButtonControl
Visual Basic(用法)
Dim instance As Button
C#
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] 
public class Button : ButtonBase, IButtonControl
C++
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] 
public ref class Button : public ButtonBase, IButtonControl
J#
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
public class Button extends ButtonBase implements IButtonControl
JScript
ComVisibleAttribute(true) 
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
public class Button extends ButtonBase implements IButtonControl

如果某个 Button 具有焦点,则可以使用鼠标、Enter 键或空格键单击该按钮。

设置 FormAcceptButtonCancelButton 属性,使用户能够通过按 Enter 或 Esc 键来单击按钮(即使该按钮没有焦点)。这使该窗体具有对话框的行为。

当使用 ShowDialog 方法显示一个窗体时,可以使用按钮的 DialogResult 属性指定 ShowDialog 的返回值。

可以更改按钮的外观。例如,要使它显示为 Web 风格的平面外观,请将 FlatStyle 属性设置为 FlatStyle.FlatFlatStyle 属性还可设置为 FlatStyle.Popup;当鼠标指针经过该按钮时,它不再是平面外观,而是将呈现标准的 Windows 按钮外观。

Note注意

如果具有焦点的控件接受并处理按 Enter 键的操作,则 Button 不处理此操作。例如,如果某个多行的 TextBox 控件或其他按钮具有焦点,则该控件将处理按 Enter 键的操作,而非“接受”按钮处理此操作。

下面的代码示例创建一个 Button,将其 DialogResult 属性设置为 DialogResult.OK,并将其添加到 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^ 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 );
   }
J#
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
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);
 }
 
System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Windows.Forms.Control
         System.Windows.Forms.ButtonBase
          System.Windows.Forms.Button
此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

Windows 98、Windows 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

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0
社区内容   什么是社区内容?
添加新内容 RSS  批注
Processing
© 2009 Microsoft Corporation 版权所有。 保留所有权利  |  商标  |  隐私权声明
Page view tracker