Control.Enabled 属性 
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置一个值,该值指示控件是否可以对用户交互作出响应。
public:
 property bool Enabled { bool get(); void set(bool value); };public bool Enabled { get; set; }member this.Enabled : bool with get, setPublic Property Enabled As Boolean属性值
如果控件可以对用户交互作出响应,则为 true;否则为 false。 默认值为 true。
示例
下面的代码示例创建并 GroupBox 设置其一些常见属性。 该示例在 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 禁用控件中包含的任何控件,则不会引发任何事件。
备注
禁用可滚动控件时,也会禁用滚动条。 例如,禁用的多行文本框无法滚动以显示所有文本行。