Control.ForeColor プロパティ

定義

コントロールの前景色を取得または設定します。

public:
 virtual property System::Drawing::Color ForeColor { System::Drawing::Color get(); void set(System::Drawing::Color value); };
public virtual System.Drawing.Color ForeColor { get; set; }
member this.ForeColor : System.Drawing.Color with get, set
Public Overridable Property ForeColor As Color

プロパティ値

Color

コントロールの前景の Color。 既定値は DefaultForeColor プロパティの値です。

次のコード例では、 BackColor コントロールと ForeColor コントロールの色を既定のシステムカラーに設定します。 コントロールに子コントロールがある場合、コードは再帰的に自身を呼び出します。 このコード例では、少なくとも 1 つの子コントロールを持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

注釈

プロパティは ForeColor アンビエント プロパティです。 アンビエント プロパティは、設定されていない場合は親コントロールから取得されるコントロール プロパティです。 たとえば、a Button は既定で親Formと同じBackColorになります。 アンビエント プロパティの詳細については、クラスまたはクラスの AmbientProperties 概要を Control 参照してください。

注意 (継承者)

派生クラスのプロパティをオーバーライドする ForeColor 場合は、基底クラスの ForeColor プロパティを使用して基本実装を拡張します。 それ以外の場合は、すべての実装を指定する必要があります。 プロパティのアクセサーとsetアクセサーのForeColor両方をgetオーバーライドする必要はありません。必要に応じて 1 つだけオーバーライドできます。

適用対象

こちらもご覧ください