Aracılığıyla paylaş


Control.HasChildren Özellik

Tanım

Denetimin bir veya daha fazla alt denetim içerdiğini belirten bir değer alır.

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

Özellik Değeri

true denetim bir veya daha fazla alt denetim içeriyorsa; aksi takdirde , false.

Öznitelikler

Örnekler

Aşağıdaki kod örneği, denetimlerin BackColor ve ForeColor değerlerini varsayılan sistem renklerine ayarlar. Denetimin alt denetimleri varsa kod özyinelemeli olarak kendisini çağırır. Bu kod örneğinde en az bir Form alt denetime sahip olmanız gerekir; ancak kendi alt denetimlerine sahip veya GroupBoxgibi bir Panel alt kapsayıcı denetimi özyineleme işlemini daha iyi gösterebilir.

   // 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

Açıklamalar

Koleksiyon Count sıfırdan Controls büyükse özelliği HasChildren döndürürtrue. özelliğine HasChildren erişmek, denetimin alt öğe içermemesi durumunda bir Control.ControlCollection oluşturulmasını zorlamaz, bu nedenle bu özelliğe başvurmak denetim ağacını yürürken bir performans avantajı sağlayabilir.

Şunlara uygulanır

Ayrıca bkz.