Control.Enabled プロパティ

定義

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

public:
 property bool Enabled { bool get(); void set(bool value); };
public bool Enabled { get; set; }
member this.Enabled : bool with get, set
Public Property Enabled As Boolean

プロパティ値

Boolean

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

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

   // 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 );
   }
// 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);
}
' 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

注釈

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

重要

プロパティを Enabled 設定しても、 false アプリケーションのコントロール ボックスが無効にならないか、アプリケーション ウィンドウがフォーカスを受け取らないようにします。

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

注意

スクロール可能なコントロールを無効にすると、スクロール バーも無効になります。 たとえば、無効になっている複数行のテキスト ボックスをスクロールして、すべてのテキスト行を表示することはできません。

適用対象

こちらもご覧ください