Control.Controls 属性


获取包含在控件内的控件的集合。Gets the collection of controls contained within the control.

 property System::Windows::Forms::Control::ControlCollection ^ Controls { System::Windows::Forms::Control::ControlCollection ^ get(); };
public System.Windows.Forms.Control.ControlCollection Controls { get; }
member this.Controls : System.Windows.Forms.Control.ControlCollection
Public ReadOnly Property Controls As Control.ControlCollection



Control.ControlCollection,它表示控件内包含的控件的集合。A Control.ControlCollection representing the collection of controls contained within the control.



下面的代码示例 ControlControl.ControlCollection 派生类的派生类中移除, Panel 前提是它是集合的成员。The following code example removes a Control from the Control.ControlCollection of the derived class Panel if it is a member of the collection. 该示例要求你已在中创建了一个 Panel 、一个 Button 和至少一个 RadioButton 控件 FormThe example requires that you have created a Panel, a Button, and at least one RadioButton control on a Form. RadioButton (s) 控件添加到 Panel 控件,并将 Panel 控件添加到 FormThe RadioButton control(s) are added to the Panel control, and the Panel control added to the Form. 单击该按钮时, removeButton 会从中删除名为的单选按钮 Control.ControlCollectionWhen the button is clicked, the radio button named removeButton is removed from the Control.ControlCollection.

   // Remove the RadioButton control if it exists.
   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)
' 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
    End If
End Sub


Control可充当控件集合的父级。A Control can act as a parent to a collection of controls. 例如,在将多个控件添加到 Form 中时,每个控件都是 Control.ControlCollection 分配给 Controls 窗体的属性的成员,该属性派生自 Control 类。For example, when several controls are added to a Form, each of the controls is a member of the Control.ControlCollection assigned to the Controls property of the form, which is derived from the Control class.

可以 Control.ControlCollection Controls 通过使用类中提供的方法来操作分配给属性的中的控件 Control.ControlCollectionYou can manipulate the controls in the Control.ControlCollection assigned to the Controls property by using the methods available in the Control.ControlCollection class.

向父控件添加几个控件时,建议您在 SuspendLayout 初始化要添加的控件之前调用方法。When adding several controls to a parent control, it is recommended that you call the SuspendLayout method before initializing the controls to be added. 向父控件添加控件后,调用 ResumeLayout 方法。After adding the controls to the parent control, call the ResumeLayout method. 这样做将提高具有许多控件的应用程序的性能。Doing so will increase the performance of applications with many controls.

使用 Controls 属性来循环访问窗体的所有控件,包括嵌套控件。Use the Controls property to iterate through all controls of a form, including nested controls. 使用 GetNextControl 方法按 tab 键顺序检索上一个或下一个子控件。Use the GetNextControl method to retrieve the previous or next child control in the tab order. 使用 ActiveControl 属性可获取或设置容器控件的活动控件。Use the ActiveControl property to get or set the active control of a container control.