System.Windows.Forms 名前空間


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

継承階層

System..::.Object
  System..::.MarshalByRefObject
    System.ComponentModel..::.Component
      System.Windows.Forms..::.Control
        System.Windows.Forms..::.ButtonBase
          System.Windows.Forms..::.Button
スレッド セーフ

この型のすべてのパブリック 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
参照

参照

タグ :


Page view tracker