WebControl.BackColor Property

Definition

获取或设置 Web 服务器控件的背景色。Gets or sets the background color of the Web server control.

public:
 virtual property System::Drawing::Color BackColor { System::Drawing::Color get(); void set(System::Drawing::Color value); };
[System.ComponentModel.TypeConverter(typeof(System.Web.UI.WebControls.WebColorConverter))]
[System.ComponentModel.Bindable(true)]
public virtual System.Drawing.Color BackColor { get; set; }
[System.ComponentModel.TypeConverter(typeof(System.Web.UI.WebControls.WebColorConverter))]
public virtual System.Drawing.Color BackColor { get; set; }
member this.BackColor : System.Drawing.Color with get, set
Public Overridable Property BackColor As Color

Property Value

Color

表示控件背景色的 ColorA Color that represents the background color of the control. 默认值为 Empty,指示未设置此属性。The default is Empty, which indicates that this property is not set.

Attributes

Examples

下面的示例演示如何设置 Table 控件的 BackColor 属性,该属性是从 WebControl 基类继承的。The following example illustrates how to set the BackColor property of the Table control, which is inherited from the WebControl base class.

<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>BackColor Property</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h3>BackColor Property of a Web Control</h3>
 
        <asp:Table id="Table1" runat="server"
            CellPadding = "10" 
            GridLines="Both"
            BackColor="LightBlue">
            <asp:TableRow>
                <asp:TableCell>
                    Row 0, Col 0
                </asp:TableCell>
                <asp:TableCell>
                    Row 0, Col 1
                </asp:TableCell>
            </asp:TableRow>
            <asp:TableRow>
                <asp:TableCell>
                    Row 1, Col 0
                </asp:TableCell>
                <asp:TableCell>
                    Row 1, Col 1
                </asp:TableCell>
            </asp:TableRow>
        </asp:Table>
    </div>
    </form>
</body>
</html>
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>BackColor Property</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h3>BackColor Property of a Web Control</h3>
 
        <asp:Table id="Table1" runat="server"
            CellPadding = "10" 
            GridLines="Both"
            BackColor="LightBlue">
            <asp:TableRow>
                <asp:TableCell>
                    Row 0, Col 0
                </asp:TableCell>
                <asp:TableCell>
                    Row 0, Col 1
                </asp:TableCell>
            </asp:TableRow>
            <asp:TableRow>
                <asp:TableCell>
                    Row 1, Col 0
                </asp:TableCell>
                <asp:TableCell>
                    Row 1, Col 1
                </asp:TableCell>
            </asp:TableRow>
        </asp:Table>
    </div>
    </form>
</body>
</html>

Remarks

使用 BackColor 属性指定 Web 服务器控件的背景色。Use the BackColor property to specify the background color of the Web server control. 使用 System.Drawing.Color 对象设置此属性。This property is set using a System.Drawing.Color object.

Note

此属性将仅为某些控件呈现。This property will render for only certain controls. 例如,TablePanelDataGridCalendarValidationSummary 将呈现此属性。For example, Table, Panel, DataGrid, Calendar, and ValidationSummary will render this property. 如果 CheckBoxListRadioButtonListDataList (如果 RepeatLayout 属性为 RepeatLayout.Table,而不是 RepeatLayout.Flow),则它也适用。It will also work for CheckBoxList, RadioButtonList and DataList if their RepeatLayout property is RepeatLayout.Table, not RepeatLayout.Flow.

通常,仅呈现为 <table> 标记的控件可以在 HTML 3.2 中显示背景色,而几乎任何控件都可以在 HTML 4.0 中显示。In general, only controls that render as a <table> tag can display a background color in HTML 3.2, whereas almost any control can in HTML 4.0.

对于呈现为 <span> 标记(包括 Label、所有验证控件以及其 RepeatLayout 属性设置为 RepeatLayout.Flow的列表控件)的控件,此属性将在 Microsoft Internet Explorer 版本5和更高版本中运行,但不能在 Microsoft Internet Explorer 版本4中使用。For controls that render as a <span> tag (including Label, all validation controls, and list controls with their RepeatLayout property set to RepeatLayout.Flow), this property will work in Microsoft Internet Explorer version 5 and later, but not in Microsoft Internet Explorer version 4.

Applies to

See also