System.Web.UI.WebControls Namespace WebControl Class
Sets or retrieves the color of the object's text.
Inline |
<asp:control ForeColor = strColor ... > |
Script |
WebControl.ForeColor [ = strColor ] |
strColor |
A System.Drawing.Color that represents the foreground color of the control, using any of the standard .NET color identifiers. See Color Table. |
This property is read/write and returns an empty string if not set.
ForeColor is used to specify the color of the textual content ( the foreground color ) of a Web server control. This property is set using a System.Drawing.Color object, the possible range of values of which are specified in this workshop's Color Table.
The following example shows how to declaratively set the ForeColor property of a Web control at design time.
<asp:button id = "myButton" runat = "server" text = "Reload"
backcolor = "maroon" forecolor = "gold" font-bold />
The example below shows how to programmatically set the ForeColor property at run time, depending on user input. The code also demonstrates how simple it is to retrieve the available colors in .NET ( via the KnownColor enum ), and dynamically add each to a selectable list.
void Page_Load ( Object src, EventArgs e ) {
if ( !IsPostBack ) {
Array colors = Enum.GetValues ( typeof ( KnownColor ) );
foreach ( KnownColor k in colors ) {
Color c = Color.FromKnownColor ( k );
if ( !c.IsSystemColor )
colorSelect.Items.Add ( c.Name );
}
}
myTable.ForeColor = Color.FromName ( colorSelect.SelectedItem.Text );
}
Show me
The following example allows a user to dynamically preview various ForeColor and BackColor combinations.
Show me
WebControl Members Style Base Web Control Properties