Control.Controls 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取控件中包含的控件的集合。
public:
property System::Windows::Forms::Control::ControlCollection ^ Controls { System::Windows::Forms::Control::ControlCollection ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.Control.ControlCollection Controls { get; }
[<System.ComponentModel.Browsable(false)>]
member this.Controls : System.Windows.Forms.Control.ControlCollection
Public ReadOnly Property Controls As Control.ControlCollection
属性值
一个 Control.ControlCollection 表示控件中包含的控件的集合。
- 属性
示例
下面的代码示例从派生类Panel中删除 a ControlControl.ControlCollection(如果它是集合的成员)。 该示例要求你在一个控件上创建了一个Panel、一个Button控件和至少一个FormRadioButton控件。 控件 RadioButton 将添加到 Panel 控件,并将 Panel 控件添加到控件中 Form。 单击该按钮时,将从中Control.ControlCollection删除名为removeButton的单选按钮。
// Remove the RadioButton control if it exists.
private:
void removeButton_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
if ( panel1->Controls->Contains( removeButton ) )
{
panel1->Controls->Remove( removeButton );
}
}
// Remove the RadioButton control if it exists.
private void removeButton_Click(object sender, System.EventArgs e)
{
if(panel1.Controls.Contains(removeButton))
{
panel1.Controls.Remove(removeButton);
}
}
' Remove the RadioButton control if it exists.
Private Sub RemoveButton_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles RemoveButton.Click
If Panel1.Controls.Contains(RemoveButton) Then
Panel1.Controls.Remove(RemoveButton)
End If
End Sub
注解
A Control 可以充当控件集合的父级。 例如,将多个控件添加到一个Form控件时,每个控件都是分配给Controls窗体属性的成员Control.ControlCollection,该属性派生自Control该类。
可以使用类中提供的方法操作分配给Controls属性的Control.ControlCollection控件Control.ControlCollection。
将多个控件添加到父控件时,建议在初始化要添加的控件之前调用 SuspendLayout 该方法。 将控件添加到父控件后,调用 ResumeLayout 该方法。 这样做将提高具有许多控件的应用程序的性能。
Controls使用属性循环访问窗体的所有控件,包括嵌套控件。 GetNextControl使用该方法检索 Tab 键顺序中的上一个或下一个子控件。 使用 ActiveControl 属性获取或设置容器控件的活动控件。