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

屬性值

Color,代表控制項的背景色彩。A Color that represents the background color of the control. 預設值為 Empty,表示這個屬性尚未設定。The default is Empty, which indicates that this property is not set.

屬性

範例

下列範例說明如何設定BackColor Table控制項的屬性,而此控制項繼承自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>

備註

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例如,ValidationSummary 、、、和會轉譯這個屬性。 Panel DataGrid CalendarFor example, Table, Panel, DataGrid, Calendar, and ValidationSummary will render this property. 它也適用于, CheckBoxList RadioButtonList如果其DataList RepeatLayout屬性為,則為, RepeatLayout.Flow而不是RepeatLayout.TableIt 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.

適用於

另請參閱