Control.ForeColor Control.ForeColor Control.ForeColor Control.ForeColor Property


获取或设置控件的前景色。Gets or sets the foreground color of the control.

 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


控件的前景 ColorThe foreground Color of the control. 默认为 DefaultForeColor 属性的值。The default is the value of the DefaultForeColor property.


下面的代码示例设置BackColorForeColor的默认系统颜色的控件。The following code example sets the BackColor and ForeColor of the controls to the default system colors. 如果控件具有任何子控件,则代码以递归方式调用自身。The code recursively calls itself if the control has any child controls. 此代码示例,则需要Form与至少一个子控件; 但是,在子容器控件,如PanelGroupBox,具有其自己的子控件包装会更好地演示递归。This code example requires that you have a Form with at least one child control; however, a child container control, like a Panel or GroupBox, with its own child control(s) would better demonstrate the recursion.

   // Reset all the controls to the user's default Control color.
   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;
      // Recursively call this method for each child control.
      foreach(Control childControl in control.Controls)
' 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
      Next childControl
   End If
End Sub


ForeColor属性是一个环境属性。The ForeColor property is an ambient property. 环境属性是控件属性,如果未设置,检索从父控件。An ambient property is a control property that, if not set, is retrieved from the parent control. 例如,Button具有相同BackColor作为其父Form默认情况下。For example, a Button will have the same BackColor as its parent Form by default. 有关环境属性的详细信息,请参阅AmbientProperties类或Control类概述。For more information about ambient properties, see the AmbientProperties class or the Control class overview.


重写时ForeColor属性在派生类中,使用基类的ForeColor属性扩展的基实现。When overriding the ForeColor property in a derived class, use the base class's ForeColor property to extend the base implementation. 否则,必须提供所有的实现。Otherwise, you must provide all the implementation. 不需要重写二者getset访问器ForeColor属性; 您可以根据需要覆盖只有一个。You are not required to override both the get and set accessors of the ForeColor property; you can override only one if needed.