共用方式為


WebControl.BackColor 屬性

定義

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

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 A 代表控制項的背景色。 預設值為 Empty,表示此性質未被設定。

屬性

範例

以下範例說明如何設定 BackColor 控制項的屬性,該屬性 Table 是繼承自 WebControl 基底類別的。

<%@ 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 來指定網頁伺服器控制項的背景色。 此屬性是透過物件 System.Drawing.Color 設定的。

備註

此特性僅適用於特定控制項。 例如,Table, , PanelDataGridCalendar, , 將ValidationSummary呈現此性質。 它也 CheckBoxList適用於 , RadioButtonListDataList 若其 RepeatLayout 性質為 RepeatLayout.Table,則不成立 RepeatLayout.Flow

一般來說,只有渲染為 <table> 標籤的控制項在 HTML 3.2 中能顯示背景色,而在 HTML 4.0 中幾乎所有控制項都可以。

對於以標籤形式呈現 <span> 的控制項(包括 Label所有驗證控制項,以及屬性 RepeatLayout 設為 RepeatLayout.Flow的清單控制項),此屬性可在 Microsoft Internet Explorer 版本 5 及以上版本中運作,但在 Microsoft Internet Explorer 版本 4 中則無法使用。

適用於

另請參閱