クリックして評価とフィードバックをお寄せください
MSDN
MSDN ライブラリ
.NET 開発
.NET Framework 3.5
.NET Framework 3.5
System.Windows.Forms 名前空間
Control クラス
Control プロパティ
 Enabled プロパティ
すべて縮小/すべて展開 すべて縮小
このページは次のバージョンについて記述しています。
Microsoft Visual Studio 2008/.NET Framework 3.5

その他のバージョンについては、以下の情報を参照してください。
.NET Framework クラス ライブラリ
Control..::.Enabled プロパティ

更新 : 2007 年 11 月

コントロールがユーザーとの対話に応答できるかどうかを示す値を取得または設定します。

名前空間 :  System.Windows.Forms
アセンブリ :  System.Windows.Forms (System.Windows.Forms.dll 内)

Visual Basic (宣言)
Public Property Enabled As Boolean
Visual Basic (使用法)
Dim instance As Control
Dim value As Boolean

value = instance.Enabled

instance.Enabled = value
C#
public bool Enabled { get; set; }
Visual C++
public:
property bool Enabled {
    bool get ();
    void set (bool value);
}
J#
/** @property */
public boolean get_Enabled()
/** @property */
public  void set_Enabled(boolean value)
JScript
public function get Enabled () : boolean
public function set Enabled (value : boolean)

プロパティ値

型 : System..::.Boolean

コントロールがユーザーとの対話に応答できる場合は true。それ以外の場合は false。既定値は true です。

Enabled プロパティを使用すると、実行時にコントロールを有効または無効にできます。たとえば、アプリケーションの現在の状態に適用されないコントロールは無効にすることができます。また、使用を制限するために、コントロールを無効にすることもできます。たとえば、ボタンを無効にして、ユーザーがクリックできないようにすることができます。コントロールが無効にされている場合は、選択できません。

重要 :

Enabled プロパティを false に設定したからといって、アプリケーションのコントロール ボックスが無効になったり、アプリケーション ウィンドウがフォーカスを受け取らなくなるわけではありません。

コンテナ コントロールの有効にされたプロパティが false に設定されているときは、そのコンテナ内のすべてコントロールも無効です。たとえば、無効にされている GroupBox コントロール内のどのコントロールをユーザーがクリックしても、イベントは発生しません。

メモ :

スクロールできるコントロールが無効にされている場合は、スクロール バーも無効です。たとえば、複数行のテキスト ボックスが無効にされている場合は、スクロールしてテキストの全行を表示することはできません。

GroupBox を作成して、共通プロパティの一部を設定するコード例を次に示します。この例では、TextBox を作成し、グループ ボックス内での Location を設定しています。次に、グループ ボックスの Text プロパティを設定して、グループ ボックスをフォームの上部にドッキングします。最後に、Enabled プロパティを false に設定してグループを無効にします。これにより、グループ ボックスに含まれるすべてのコントロールが無効になります。

Visual Basic
' Add a GroupBox to a form and set some of its common properties.
Private Sub AddMyGroupBox()
   ' Create a GroupBox and add a TextBox to it.
   Dim groupBox1 As New GroupBox()
   Dim textBox1 As New TextBox()
   textBox1.Location = New Point(15, 15)
   groupBox1.Controls.Add(textBox1)

   ' Set the Text and Dock properties of the GroupBox.
   groupBox1.Text = "MyGroupBox"
   groupBox1.Dock = DockStyle.Top

   ' Disable the GroupBox (which disables all its child controls)
   groupBox1.Enabled = False

   ' Add the Groupbox to the form.
   Me.Controls.Add(groupBox1)
End Sub
C#
// Add a GroupBox to a form and set some of its common properties.
private void AddMyGroupBox()
{
   // Create a GroupBox and add a TextBox to it.
   GroupBox groupBox1 = new GroupBox();
   TextBox textBox1 = new TextBox();
   textBox1.Location = new Point(15, 15);
   groupBox1.Controls.Add(textBox1);

   // Set the Text and Dock properties of the GroupBox.
   groupBox1.Text = "MyGroupBox";
   groupBox1.Dock = DockStyle.Top;

   // Disable the GroupBox (which disables all its child controls)
   groupBox1.Enabled = false;

   // Add the Groupbox to the form.
   this.Controls.Add(groupBox1);
}
Visual C++
   // Add a GroupBox to a form and set some of its common properties.
private:
   void AddMyGroupBox()
   {
      // Create a GroupBox and add a TextBox to it.
      GroupBox^ groupBox1 = gcnew GroupBox;
      TextBox^ textBox1 = gcnew TextBox;
      textBox1->Location = Point(15,15);
      groupBox1->Controls->Add( textBox1 );

      // Set the Text and Dock properties of the GroupBox.
      groupBox1->Text = "MyGroupBox";
      groupBox1->Dock = DockStyle::Top;

      // Disable the GroupBox (which disables all its child controls)
      groupBox1->Enabled = false;

      // Add the Groupbox to the form.
      this->Controls->Add( groupBox1 );
   }
J#
// Add a GroupBox to a form and set some of its common properties.
private void AddMyGroupBox()
{
    // Create a GroupBox and add a TextBox to it.
    GroupBox groupBox1 = new GroupBox();
    TextBox textBox1 = new TextBox();
    textBox1.set_Location(new Point(15, 15));
    groupBox1.get_Controls().Add(textBox1);
    // Set the Text and Dock properties of the GroupBox.
    groupBox1.set_Text("MyGroupBox");
    groupBox1.set_Dock(DockStyle.Top);
    // Disable the GroupBox (which disables all its child controls)
    groupBox1.set_Enabled(false);
    // Add the Groupbox to the form.
    this.get_Controls().Add(groupBox1);
} //AddMyGroupBox

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 Smartphone, 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