WebControl.BorderStyle 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置 Web 服务器控件的边框样式。
public:
virtual property System::Web::UI::WebControls::BorderStyle BorderStyle { System::Web::UI::WebControls::BorderStyle get(); void set(System::Web::UI::WebControls::BorderStyle value); };
[System.ComponentModel.Bindable(true)]
public virtual System.Web.UI.WebControls.BorderStyle BorderStyle { get; set; }
public virtual System.Web.UI.WebControls.BorderStyle BorderStyle { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.BorderStyle : System.Web.UI.WebControls.BorderStyle with get, set
member this.BorderStyle : System.Web.UI.WebControls.BorderStyle with get, set
Public Overridable Property BorderStyle As BorderStyle
属性值
BorderStyle 枚举值之一。 默认值为 NotSet
。
- 属性
示例
下面的示例演示如何设置 BorderStyle 从基类继承的 Table 控件的 WebControl 属性。
<%@ Page Language="C#" %>
<!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>BorderStyle Property</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3>BorderStyle Property of a Web Control</h3>
<asp:Table id="Table1" runat="server"
CellPadding = "10"
CellSpacing="0"
GridLines="Both"
BorderWidth="3"
BorderColor="Red"
BorderStyle="dashed">
<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>BorderStyle Property</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3>BorderStyle Property of a Web Control</h3>
<asp:Table id="Table1" runat="server"
CellPadding = "10"
CellSpacing="0"
GridLines="Both"
BorderWidth="3"
BorderColor="Red"
BorderStyle="dashed">
<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>
注意
下面的代码示例使用单文件代码模型,如果直接复制到代码隐藏文件中,可能无法正常工作。 此代码示例必须复制到扩展名为 .aspx 的空文本文件中。 有关 Web 窗体代码模型的详细信息,请参阅 ASP.NET Web 窗体页代码模型。
<!-- This example demonstrates how to set property values for the
BorderColor, BorderStyle, and BorderWidth properties, and how to
change the property values at run time. -->
<!-- This example demonstrates how to set property values for the
BorderColor, BorderStyle, and BorderWidth properties, and how to
change the property values at run time. -->
<%@ Page language="c#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Drawing" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
// Determine whether this is the first time the page is loaded;
// if so, load the drop-down lists with data.
if (!Page.IsPostBack)
{
// <Snippet4>
// Create a ListItemCollection and add names of colors.
ListItemCollection colors = new ListItemCollection();
colors.Add(Color.Black.Name);
colors.Add(Color.Blue.Name);
colors.Add(Color.Green.Name);
colors.Add(Color.Orange.Name);
colors.Add(Color.Purple.Name);
colors.Add(Color.Red.Name);
colors.Add(Color.White.Name);
colors.Add(Color.Yellow.Name);
// </Snippet4>
// Bind the colors collection to the borderColorList.
borderColorList.DataSource = colors;
borderColorList.DataBind();
// Create a ListItemCollection and the add names of
// the BorderStyle enumeration values.
ListItemCollection styles = new ListItemCollection();
foreach (string s in Enum.GetNames(typeof(BorderStyle)))
{
styles.Add(s);
}
// Bind the styles collection to the borderStyleList.
borderStyleList.DataSource = styles;
borderStyleList.DataBind();
// Create a ListItemCollection and add width values
// expressed in pixels (px).
ListItemCollection widths = new ListItemCollection();
for (int i = 0; i < 11; i++)
{
widths.Add(i.ToString() + "px");
}
// Bind the widths collection to the borderWidthList.
borderWidthList.DataSource = widths;
borderWidthList.DataBind();
}
}
// This method handles the SelectedIndexChanged event for borderColorList.
public void ChangeBorderColor(object sender, System.EventArgs e)
{
// <Snippet5>
// Convert the color name string to an object of type Color,
// and set the Color as the new border color for Label1.
Label1.BorderColor = Color.FromName(borderColorList.SelectedItem.Text);
// </Snippet5>
}
// This method handles the selectedIndexChanged event for boderStyleList.
public void ChangeBorderStyle(object sender, System.EventArgs e)
{
// <Snippet6>
// Convert the style name string to a BorderStyle enumeration value,
// and set the BorderStyle as the new border style for Label1.
Label1.BorderStyle = (BorderStyle)Enum.Parse(typeof(BorderStyle),
borderStyleList.SelectedItem.Text);
// </Snippet6>
}
// This method handles the SelectedIndexChanged event for borderWidthList.
public void ChangeBorderWidth(object sender, System.EventArgs e)
{
// <Snippet7>
// Convert the border width string to a object of type Unit,
// and set the Unit as the new border width for Label1.
Label1.BorderWidth = Unit.Parse(borderWidthList.SelectedItem.Text);
// </Snippet7>
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title> Border Properties Example </title>
</head>
<body>
<form id="form1" runat="server">
<h3> Border Properties Example </h3>
<table border="0" cellpadding="6">
<tr>
<td>
<asp:Label Runat="server" BorderColor="Black"
BorderStyle="Solid" BorderWidth="4px" ID="Label1"
Text="Border Properties Example" Height="75"
Width="200"><center><br />Border Properties Example
</center></asp:Label>
</td>
<td>
<asp:DropDownList Runat="server" ID="borderColorList"
OnSelectedIndexChanged="ChangeBorderColor" AutoPostBack="True"
EnableViewState="True"></asp:DropDownList>
<br />
<br />
<asp:DropDownList Runat="server" ID="borderStyleList"
OnSelectedIndexChanged="ChangeBorderStyle" AutoPostBack="True"
EnableViewState="True"></asp:DropDownList>
<br />
<br />
<asp:DropDownList Runat="server" ID="borderWidthList"
OnSelectedIndexChanged="ChangeBorderWidth" AutoPostBack="True"
EnableViewState="True"></asp:DropDownList>
</td>
</tr>
</table>
</form>
</body>
</html>
<%@ Page language="VB" AutoEventWireup="true" %>
<%@ Import Namespace="System.Drawing" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Private Sub Page_Load(sender As Object, e As System.EventArgs)
' Determine whether this is the first time the page is loaded;
' if so, load the drop-down lists with data.
If Not Page.IsPostBack Then
'<Snippet4>
' Create a ListItemCollection and add names of colors.
Dim colors As New ListItemCollection()
colors.Add(Color.Black.Name)
colors.Add(Color.Blue.Name)
colors.Add(Color.Green.Name)
colors.Add(Color.Orange.Name)
colors.Add(Color.Purple.Name)
colors.Add(Color.Red.Name)
colors.Add(Color.White.Name)
colors.Add(Color.Yellow.Name)
'</Snippet4>
' Bind the colors collection to the borderColorList.
borderColorList.DataSource = colors
borderColorList.DataBind()
' Create a ListItemCollection and the add names of
' the BorderStyle enumeration values.
Dim styles As New ListItemCollection()
Dim styleType As Type = GetType(BorderStyle)
Dim s As String
For Each s In [Enum].GetNames(styleType)
styles.Add(s)
Next s
' Bind the styles collection to the borderStyleList.
borderStyleList.DataSource = styles
borderStyleList.DataBind()
' Create a ListItemCollection and add width values
' expressed in pixels (px).
Dim widths As New ListItemCollection()
Dim i As Integer
For i = 0 To 10
widths.Add(i.ToString() & "px")
Next i
' Bind the widths collection to the borderWidthList.
borderWidthList.DataSource = widths
borderWidthList.DataBind()
End If
End Sub
' This method handles the SelectedIndexChanged event for borderColorList.
Public Sub ChangeBorderColor(sender As Object, e As System.EventArgs)
'<Snippet5>
' Convert the color name string to an object of type Color,
' and set the Color as the new border color for Label1.
Label1.BorderColor = Color.FromName(borderColorList.SelectedItem.Text)
'</Snippet5>
End Sub
' This method handles the selectedIndexChanged event for boderStyleList.
Public Sub ChangeBorderStyle(sender As Object, e As System.EventArgs)
'<Snippet6>
' Convert the style name string to a BorderStyle enumeration value,
' and set the BorderStyle as the new border style for Label1.
Dim styleType As Type = GetType(BorderStyle)
Label1.BorderStyle = [Enum].Parse(styleType, borderStyleList.SelectedItem.Text)
'</Snippet6>
End Sub
' This method handles the SelectedIndexChanged event for borderWidthList.
Public Sub ChangeBorderWidth(sender As Object, e As System.EventArgs)
'<Snippet7>
' Convert the border width string to a object of type Unit,
' and set the Unit as the new border width for Label1.
Label1.BorderWidth = Unit.Parse(borderWidthList.SelectedItem.Text)
'</Snippet7>
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title> Border Properties Example </title>
</head>
<body>
<form id="form1" runat="server">
<h3> Border Properties Example </h3>
<table border="0" cellpadding="6">
<tr>
<td>
<asp:Label Runat="server" BorderColor="Black"
BorderStyle="Solid" BorderWidth="4px" ID="Label1"
Text="Border Properties Example" Height="75"
Width="200"><center><br />Border Properties Example
</center></asp:Label>
</td>
<td>
<asp:DropDownList Runat="server" ID="borderColorList"
OnSelectedIndexChanged="ChangeBorderColor" AutoPostBack="True"
EnableViewState="True"></asp:DropDownList>
<br />
<br />
<asp:DropDownList Runat="server" ID="borderStyleList"
OnSelectedIndexChanged="ChangeBorderStyle" AutoPostBack="True"
EnableViewState="True"></asp:DropDownList>
<br />
<br />
<asp:DropDownList Runat="server" ID="borderWidthList"
OnSelectedIndexChanged="ChangeBorderWidth" AutoPostBack="True"
EnableViewState="True"></asp:DropDownList>
</td>
</tr>
</table>
</form>
</body>
</html>
注解
BorderStyle使用 属性指定 Web 服务器控件的边框样式。 此属性是使用枚举值之一设置的 BorderStyle 。 下表列出了可能的值。
边框样式 | 说明 |
---|---|
NotSet |
未设置边框样式。 |
None |
无边框 |
Dotted |
虚线边框。 |
Dashed |
点划线边框。 |
Solid |
实线边框。 |
Double |
实心双线边框。 |
Groove |
用于凹陷边框外观的凹槽状边框。 |
Ridge |
用于凸起边框外观的突起边框。 |
Inset |
用于凹陷控件外观的内嵌边框。 |
Outset |
用于凸起控件外观的外嵌边框。 |
注意
对于任何 Web 服务器控件,此属性不会在早于 Microsoft Internet Explorer 4 的浏览器上呈现。 HTML 3.2 中没有等效项。