WebControl.BackColor 属性

定义

获取或设置 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; }
member this.BackColor : System.Drawing.Color with get, set
Public Overridable Property BackColor As Color

属性值

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

属性

示例

下面的示例演示如何设置继承自BackColor WebControl基类的Table控件的属性。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>

注解

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.

备注

此属性将仅为某些控件呈现。This property will render for only certain controls. 例如Table ,、Panel、、和ValidationSummary将呈现此属性。 DataGrid CalendarFor example, Table, Panel, DataGrid, Calendar, and ValidationSummary will render this property. 它也适用于, CheckBoxList RadioButtonList并且DataList如果其RepeatLayout属性为RepeatLayout.TableRepeatLayout.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.

适用于

另请参阅