共用方式為


Control.Controls 屬性

定義

取得控制中包含的控制項集合。

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

屬性值

A Control.ControlCollection 代表控制項內所包含的控制項集合。

屬性

範例

以下程式碼範例若 a 是該集合的成員,則會從衍生類別Panel中移除 a。ControlControl.ControlCollection 範例要求你建立了一個 PanelButton一個 ,以及至少一個 RadioButton 控制點在 Form上。 RadioButton控制項會加入控制項PanelPanel控制項則加入到控制項。Form 當按鈕被點擊時,該名稱 removeButton 的單選按鈕會從 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

備註

A Control 可以作為一組控制的父。 例如,當多個控制項加入 時Form,每個控制項都是指派給Controls表單屬性的成員Control.ControlCollection,該表單屬性由類別衍生Control而來。

你可以利用類別中Control.ControlCollection可用的方法來操作指派給該Controls屬性的控制Control.ControlCollection項。

在父控制項中加入多個控制項時,建議在初始化要加入的控制項前先呼叫該 SuspendLayout 方法。 將控制項加入父控制項後,呼叫該 ResumeLayout 方法。 這樣做將提升擁有多種控制的應用程式效能。

利用該 Controls 屬性遍歷表單的所有控制項,包括巢狀控制項。 使用該 GetNextControl 方法取得 tab 鍵順序中的前一個或下一個子控制項。 利用這個 ActiveControl 屬性來取得或設定容器控制的主動控制。

適用於

另請參閱