Control.Enabled 属性
获取或设置一个值,该值指示控件是否可以对用户交互作出响应。
**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)
语法
声明
<LocalizableAttribute(True)> _
Public Property Enabled As Boolean
用法
Dim instance As Control
Dim value As Boolean
value = instance.Enabled
instance.Enabled = value
[LocalizableAttribute(true)]
public bool Enabled { get; set; }
[LocalizableAttribute(true)]
public:
property bool Enabled {
bool get ();
void set (bool value);
}
/** @property */
public boolean get_Enabled ()
/** @property */
public void set_Enabled (boolean value)
public function get Enabled () : boolean
public function set Enabled (value : boolean)
属性值
如果控件可以对用户交互作出响应,则为 true;否则为 false。默认为 true。
备注
通过 Enabled 属性,可以在运行时启用或禁用控件。例如,可以禁用对应用程序的当前状态不适用的那些控件。还可以禁用一个控件,以限制其使用。例如,可以禁用一个按钮,以防止用户单击它。如果控件被禁用,就无法选中它。
重要事项: |
---|
将 Enabled 属性设置为 false 不会禁用应用程序的控件框或禁止应用程序窗口接收焦点。 |
当将一个容器控件的启用属性设置为 false 时,其包含的所有控件也都被禁用。例如,如果用户单击被禁用的 GroupBox 控件包含的任何控件,不会引发任何事件。
提示
当禁用可滚动的控件时,滚动条也被禁用。例如,一个被禁用的多行文本框无法滚动以显示所有文本行。
示例
下面的代码示例创建 GroupBox 并设置该控件的一些通用属性。该示例创建一个 TextBox 并设置它在分组框中的 Location。接着,它设置分组框的 Text 属性,并将此分组框停靠在窗体的顶部。最后,它通过将 Enabled 属性设置为 false 来禁用分组框,这将导致分组框中的所有控件都被禁用。
' 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
// 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:
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.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 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
.NET Compact Framework
受以下版本支持:2.0、1.0
请参见
参考
Control 类
Control 成员
System.Windows.Forms 命名空间
ScrollableControl