MonthCalendar.ForeColor 属性

定义

获取或设置控件的前景色。

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

属性值

控件的前景 Color。 默认为 DefaultForeColor 属性的值。

示例

下面的代码示例将 BackColor 控件的 和 ForeColor 设置为默认系统颜色。 如果控件具有任何子控件,则代码以递归方式调用自身。 此代码示例要求具有 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 是环境属性。 环境属性是一个控件属性,如果未设置,将从父控件检索该属性。 例如, Button 默认具有与其父级Form相同的 BackColor 。 有关环境属性的详细信息,请参阅 AmbientProperties 类或 Control 类概述。

从 Windows Vista 开始,根据主题,设置此属性可能不会更改日历的外观。 例如,如果 Windows 设置为使用 Aero 主题,则设置此属性不起作用。 这是因为日历的更新版本以在运行时从当前操作系统主题派生的外观呈现。 如果要使用此属性并启用早期版本的日历,可以为应用程序禁用视觉样式。 禁用视觉样式可能会影响应用程序中其他控件的外观和行为。 要在 Visual Basic 中禁用视觉样式,请打开项目设计器并取消选中“启用 XP 视觉样式”复选框。 要在 C# 中禁用视觉样式,请打开 Program.cs 并注释禁止 Application.EnableVisualStyles();

继承者说明

重写派生类中的 ForeColor 属性时,使用基类的 ForeColor 属性扩展基实现。 否则,必须提供所有实现。 无需同时get重写属性的 ForeColorset 访问器;如果需要,只能重写一个访问器。

适用于

另请参阅