Control.DefaultForeColor 属性

定义

获取控件的默认前景色。Gets the default foreground color of the control.

public:
 static property System::Drawing::Color DefaultForeColor { System::Drawing::Color get(); };
public static System.Drawing.Color DefaultForeColor { get; }
member this.DefaultForeColor : System.Drawing.Color
Public Shared ReadOnly Property DefaultForeColor As Color

属性值

控件的前景 ColorThe default foreground Color of the control. 默认值为 ControlTextThe default is ControlText.

示例

下面的代码示例演示如何使用 DefaultBackColorDefaultFontDefaultForeColor 成员。The following code example demonstrates how to use the DefaultBackColor, DefaultFont, and DefaultForeColor members. 若要运行该示例,请将以下代码粘贴到包含名为 ListBox1 的 ListBox 的窗体中。To run the example, paste the following code in a form containing a ListBox called ListBox1. 在窗体的构造函数或 Load 事件处理方法中调用 Populate_ListBox 方法。Call the Populate_ListBox method in the form's constructor or Load event-handling method.

// 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.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.

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

注解

这是 nonparented 控件的默认 ForeColor 属性值。This is the default ForeColor property value of a nonparented control. 派生类可以具有不同的默认值。Derived classes can have different defaults.

适用于

另请参阅