Control.Controls Control.Controls Control.Controls Control.Controls Property

定義

取得控制項中包含的控制項集合。Gets the collection of controls contained within the control.

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; }
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控制項新增至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.
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

備註

AControl可做為控制項的集合的父系。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.ControlCollection類別。You 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方法來擷取上一個或下一步 的子控制項的定位順序。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.

適用於

另請參閱