クリックして評価とフィードバックをお寄せください
MSDN
MSDN ライブラリ
.NET 開発
.NET Framework 3.5
.NET Framework 3.5
System.Windows.Forms 名前空間
Button クラス

  低帯域幅での表示をオンにする
このページは次のバージョンについて記述しています。
Microsoft Visual Studio 2008/.NET Framework 3.5

その他のバージョンについては、以下の情報を参照してください。
.NET Framework クラス ライブラリ
Button クラス

更新 : 2007 年 11 月

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


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


この型のすべてのパブリック static (Visual Basic では Shared) メンバは、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。

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

.NET Framework および .NET Compact Framework では、各プラットフォームのすべてのバージョンはサポートしていません。サポートされているバージョンについては、「.NET Framework システム要件」を参照してください。

.NET Framework

サポート対象 : 3.5、3.0、2.0、1.1、1.0

.NET Compact Framework

サポート対象 : 3.5、2.0、1.0
コミュニティ コンテンツ   コミュニティ コンテンツとは
新しいコンテンツの追加 RSS  注釈
Processing
© 2009 Microsoft Corporation. All rights reserved. 使用条件  |  商標  |  プライバシー
Page view tracker