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

/** @property */ public Color get_BackColor () /** @property */ public void set_BackColor (Color value)
コントロールの背景色を表す Color。既定値は DefaultBackColor プロパティの値です。

System.Windows.Forms.ControlStyles の SupportsTransparentBackColor 値が true に設定されない限り、BackColor プロパティは透過色をサポートしません。
BackColor プロパティがアンビエント プロパティです。アンビエント プロパティは、コントロール プロパティです。設定しない場合は、親コントロールから取得されます。たとえば、Button は、既定では親の Form と同じ BackColor を持ちます。アンビエント プロパティの詳細については、AmbientProperties クラスまたは Control クラスの概要を参照してください。
継承時の注意 派生クラスで BackColor プロパティをオーバーライドする場合は、基本クラスの BackColor プロパティを使用して、基本の実装を拡張します。それ以外の場合は、すべての実装を提供する必要があります。BackColor プロパティの get アクセサと set アクセサの両方をオーバーライドする必要はありません。必要に応じて 1 つのアクセサだけをオーバーライドできます。
コントロールの 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.BackColor プロパティを検索する場合は、下記のリンクをクリックしてください。

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