Freigeben über


Control.HasChildren-Eigenschaft

Ruft einen Wert ab, der angibt, ob das Steuerelement ein oder mehrere untergeordnete Steuerelemente enthält.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

Syntax

'Declaration
Public ReadOnly Property HasChildren As Boolean
'Usage
Dim instance As Control
Dim value As Boolean

value = instance.HasChildren
public bool HasChildren { get; }
public:
property bool HasChildren {
    bool get ();
}
/** @property */
public boolean get_HasChildren ()
public function get HasChildren () : boolean

Eigenschaftenwert

true, wenn das Steuerelement ein oder mehrere untergeordnete Steuerelemente enthält, andernfalls false.

Hinweise

Wenn der Count der Controls-Auflistung größer als 0 (null) ist, gibt die HasChildren-Eigenschaft true zurück. Der Zugriff auf die HasChildren-Eigenschaft erzwingt nicht das Erstellen einer Control.ControlCollection, wenn das Steuerelement über keine untergeordneten Elemente verfügt. Ein Verweis auf diese Eigenschaft kann daher einen Leistungsvorteil beim Durchlaufen einer Struktur von Steuerelementen bieten.

Beispiel

Im folgenden Codebeispiel werden die BackColor und die ForeColor der Steuerelemente auf die Standardsystemfarben festgelegt. Der Code ruft sich selbst rekursiv auf, wenn das Steuerelement über untergeordnete Steuerelemente verfügt. Für dieses Codebeispiel müssen Sie über ein Form mit zumindest einem untergeordneten Steuerelement verfügen. Mit einem untergeordneten Containersteuerelement, z. B. einem Panel oder einem GroupBox, das ein oder mehrere eigene untergeordnete Steuerelemente aufweist, ließe sich die Rekursion jedoch noch besser veranschaulichen.

' 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 Me.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
// 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(this.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:
   void ResetAllControlsBackColor( Control^ control )
   {
      control->BackColor = SystemColors::Control;
      control->ForeColor = SystemColors::ControlText;
      if ( this->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.set_BackColor(SystemColors.get_Control());
    control.set_ForeColor(SystemColors.get_ControlText());
    if (this.get_HasChildren()) {
        for (int iCtr=0; iCtr < control.get_Controls().get_Count(); iCtr++) {
            // Recursively call this method for each child control.
            Control childControl = control.get_Controls().get_Item(iCtr);
            ResetAllControlsBackColor(childControl);
        }
    }
} //ResetAllControlsBackColor

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

Control-Klasse
Control-Member
System.Windows.Forms-Namespace
Count