クリックして評価とフィードバックをお寄せください
MSDN
MSDN ライブラリ
.NET 開発
以前のバージョン
.NET Framework SDK 2.0
System.Windows.Forms
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 キーまたは Space キーを使用することもできます。

FormAcceptButton プロパティまたは CancelButton プロパティを設定すると、ボタンにフォーカスがなくても Enter キーまたは Esc キーを押してボタンをクリックできます。この設定により、フォームがダイアログ ボックスとして動作します。

ShowDialog メソッドを使用してフォームを表示する場合は、ボタンの DialogResult プロパティを使用して ShowDialog の戻り値を指定します。

ボタンの外観は変更できます。たとえば、Web 用にフラットな外観にするには FlatStyle プロパティを FlatStyle.Flat に設定します。FlatStyle プロパティを FlatStyle.Popup に設定すると、マウス ポインタがボタンの上を通過するまではフラットで、通過した後は標準 Windows ボタンの外観となります。

メモメモ

フォーカスがあるコントロールが 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
この型の public static (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. All rights reserved. 使用条件  |  商標  |  プライバシー
Page view tracker