WebControl.BackColor 屬性

定義

取得或設定 Web 伺服器控制項的背景色彩。

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

屬性值

Color,代表控制項的背景色彩。 預設值為 Empty,表示這個屬性尚未設定。

屬性

範例

下列範例說明如何設定 BackColor 繼承自 WebControl 基類之 控制項的 Table 屬性。

<%@ 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 服務器控制項的背景色彩。 這個屬性是使用 System.Drawing.Color 物件來設定的。

注意

此屬性只會針對特定控制項轉譯。 例如, TablePanelDataGridCalendarValidationSummary 會轉譯這個屬性。 它也適用于 CheckBoxList ,如果其 RepeatLayout 屬性為 RepeatLayout.TableRadioButtonListDataList 則為 ,而非 RepeatLayout.Flow

一般而言,只有轉譯為 <table> 標記的控制項可以在 HTML 3.2 中顯示背景色彩,而幾乎任何控制項都可以在 HTML 4.0 中顯示。

對於轉譯為 <span> 標記的控制項 (包括 Label 、所有驗證控制項,以及其 RepeatLayout 屬性設定為 RepeatLayout.Flow) 的清單控制項,此屬性將會在 Microsoft Internet Explorer 第 5 版和更新版本中運作,但不適用於 Microsoft Internet Explorer 第 4 版。

適用於

另請參閱