WebControl.BackColor Właściwość

Definicja

Pobiera lub ustawia kolor tła kontrolki serwera sieci 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

Wartość właściwości

Element Color reprezentujący kolor tła kontrolki. Wartość domyślna to Empty, która wskazuje, że ta właściwość nie jest ustawiona.

Atrybuty

Przykłady

W poniższym przykładzie pokazano, jak ustawić BackColor właściwość kontrolki Table dziedziczonej z klasy bazowej 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>

Uwagi

Użyj właściwości , BackColor aby określić kolor tła kontrolki serwera sieci Web. Ta właściwość jest ustawiana przy użyciu System.Drawing.Color obiektu.

Uwaga

Ta właściwość będzie renderowana tylko dla niektórych kontrolek. Na przykład , Table, Panel, DataGridCalendar, i ValidationSummary spowoduje renderowanie tej właściwości. Będzie również działać dla CheckBoxList, RadioButtonList a DataList jeśli ich RepeatLayout właściwość to RepeatLayout.Table, a nie RepeatLayout.Flow.

Ogólnie rzecz biorąc, tylko kontrolki renderowane jako <table> tag mogą wyświetlać kolor tła w kodzie HTML 3.2, natomiast prawie każda kontrolka może znajdować się w kodzie HTML 4.0.

W przypadku kontrolek renderujących jako <span> tag (w tym Label, wszystkie kontrolki walidacji i kontrolki listy z ich RepeatLayout właściwością ustawioną na RepeatLayout.Flow), ta właściwość będzie działać w programie Microsoft Internet Explorer w wersji 5 lub nowszej, ale nie w programie Microsoft Internet Explorer w wersji 4.

Dotyczy

Zobacz też