Control.HasChildren プロパティ
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)


Controls コレクションの Count が 0 を超える場合、HasChildren プロパティは true を返します。HasChildren プロパティにアクセスしても、コントロールに子がない場合は Control.ControlCollection が強制的に作成されることはないため、このプロパティを参照すると、コントロールのツリーを進むときのパフォーマンスを向上できます。

コントロールの BackColor および ForeColor を既定のシステム カラーに設定するコード例を次に示します。コントロールに子コントロールがある場合、コードは再帰的に自分自身を呼び出します。このコード例では、Form に少なくとも 1 つの子コントロールが存在している必要があります。ただし、Panel または GroupBox のような、独自の子コントロールがある子コンテナ コントロールの方が、再帰の例として適しています。
' 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

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からControl.HasChildren プロパティを検索する場合は、下記のリンクをクリックしてください。

- Control.HasChildren プロパティのページへのリンク