언어

Control.HasChildren 속성

정의

컨트롤에 하나 이상의 자식 컨트롤이 포함되어 있는지 여부를 나타내는 값을 가져옵니다.

public:
 property bool HasChildren { bool get(); };
[System.ComponentModel.Browsable(false)]
public bool HasChildren { get; }
[<System.ComponentModel.Browsable(false)>]
member this.HasChildren : bool
Public ReadOnly Property HasChildren As Boolean

속성 값

true컨트롤에 하나 이상의 자식 컨트롤이 포함되어 있으면 이고, 그렇지 않으면 . false

특성

예제

다음 코드 예제에서는 컨트롤의 BackColorForeColor 기본 시스템 색으로 설정 합니다. 컨트롤에 자식 컨트롤이 있는 경우 코드가 재귀적으로 자신을 호출합니다. 이 코드 예제에서는 자식 컨트롤이 하나 이상 있어야 Form 합니다. 그러나 자식 컨트롤과 같은 PanelGroupBox자식 컨테이너 컨트롤은 자체 자식 컨트롤을 사용하여 재귀를 더 잘 보여 줍니다.

   // Reset all the controls to the user's default Control color.
private:
   void ResetAllControlsBackColor( Control^ control )
   {
      control->BackColor = SystemColors::Control;
      control->ForeColor = SystemColors::ControlText;
      if ( control->HasChildren )
      {
         // Recursively call this method for each child control.
         IEnumerator^ myEnum = control->Controls->GetEnumerator();
         while ( myEnum->MoveNext() )
         {
            Control^ childControl = safe_cast<Control^>(myEnum->Current);
            ResetAllControlsBackColor( childControl );
         }
      }
   }
// Reset all the controls to the user's default Control color. 
private void ResetAllControlsBackColor(Control control)
{
   control.BackColor = SystemColors.Control;
   control.ForeColor = SystemColors.ControlText;
   if(control.HasChildren)
   {
      // Recursively call this method for each child control.
      foreach(Control childControl in control.Controls)
      {
         ResetAllControlsBackColor(childControl);
      }
   }
}
' Reset all the controls to the user's default Control color. 
Private Sub ResetAllControlsBackColor(control As Control)
   control.BackColor = SystemColors.Control
   control.ForeColor = SystemColors.ControlText
   If control.HasChildren Then
      ' Recursively call this method for each child control.
      Dim childControl As Control
      For Each childControl In  control.Controls
         ResetAllControlsBackColor(childControl)
      Next childControl
   End If
End Sub

설명

컬렉션 Controls 이 Count 0보다 크면 속성이 HasChildren 반환true됩니다. 속성에 HasChildren 액세스해도 컨트롤에 자식이 없는 경우 강제로 생성 Control.ControlCollection 되지 않으므로 이 속성을 참조하면 컨트롤 트리를 탐색할 때 성능이 향상됩니다.

적용 대상

참고 항목