Control.DefaultForeColor 属性

获取控件的默认前景色。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Shared ReadOnly Property DefaultForeColor As Color
用法
Dim value As Color

value = Control.DefaultForeColor
public static Color DefaultForeColor { get; }
public:
static property Color DefaultForeColor {
    Color get ();
}
/** @property */
public static Color get_DefaultForeColor ()
public static function get DefaultForeColor () : Color

属性值

控件的默认前景 Color。默认为 SystemColors.ControlText

备注

这是无父级控件的默认 ForeColor 属性值。派生类可以有不同的默认设置。

示例

下面的代码示例阐释了如何使用 DefaultBackColorDefaultFontDefaultForeColor 成员。若要运行该示例,请将以下代码粘贴到一个窗体中,让该窗体包含一个名为 ListBox1 的 ListBox。在窗体的构造函数或 Load 事件处理方法中调用 Populate_ListBox 方法。

' The following method displays the default font, 
' background color and foreground color values for the ListBox  
' control. The values are displayed in the ListBox, itself.

Private Sub Populate_ListBox()
    ListBox1.Dock = DockStyle.Bottom

    ' Display the values in the read-only properties 
    ' DefaultBackColor, DefaultFont, DefaultForecolor.
    ListBox1.Items.Add("Default BackColor: " & ListBox.DefaultBackColor.ToString)
    ListBox1.Items.Add("Default Font: " & ListBox.DefaultFont.ToString)
    ListBox1.Items.Add("Default ForeColor:" & ListBox.DefaultForeColor.ToString)

End Sub
// The following method displays the default font, 
// background color and foreground color values for the ListBox  
// control. The values are displayed in the ListBox, itself.

private void Populate_ListBox()
{
    ListBox1.Dock = DockStyle.Bottom;

    // Display the values in the read-only properties 
    // DefaultBackColor, DefaultFont, DefaultForecolor.
    ListBox1.Items.Add("Default BackColor: " + 
        ListBox.DefaultBackColor.ToString());
    ListBox1.Items.Add("Default Font: " + 
        ListBox.DefaultFont.ToString());
    ListBox1.Items.Add("Default ForeColor:" + 
        ListBox.DefaultForeColor.ToString());

}
// The following method displays the default font, 
// background color and foreground color values for the ListBox  
// control. The values are displayed in the ListBox, itself.
void Populate_ListBox()
{
   ListBox1->Dock = DockStyle::Bottom;
   
   // Display the values in the read-only properties 
   // DefaultBackColor, DefaultFont, DefaultForecolor.
   ListBox1->Items->Add( String::Format( "Default BackColor: {0}", ListBox::DefaultBackColor ) );
   ListBox1->Items->Add( String::Format( "Default Font: {0}", ListBox::DefaultFont ) );
   ListBox1->Items->Add( String::Format( "Default ForeColor:{0}", ListBox::DefaultForeColor ) );
}
// The following method displays the default font, 
// background color and foreground color values for the ListBox  
// control. The values are displayed in the ListBox, itself.
private void Populate_ListBox()
{
    listBox1.set_Dock(DockStyle.Bottom);
    // Display the values in the read-only properties 
    // DefaultBackColor, DefaultFont, DefaultForecolor.
    listBox1.get_Items().Add("Default BackColor: " 
        + ListBox.get_DefaultBackColor().ToString());
    listBox1.get_Items().Add("Default Font: " 
        + ListBox.get_DefaultFont().ToString());
    listBox1.get_Items().Add("Default ForeColor:" 
        + ListBox.get_DefaultForeColor().ToString());
} //Populate_ListBox

平台

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 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

Control 类
Control 成员
System.Windows.Forms 命名空间
ForeColor
Color
SystemColors