WebControl.BorderStyle プロパティ

Web サーバー コントロールの境界線スタイルを取得または設定します。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)

構文

'宣言
Public Overridable Property BorderStyle As BorderStyle
'使用
Dim instance As WebControl
Dim value As BorderStyle

value = instance.BorderStyle

instance.BorderStyle = value
public virtual BorderStyle BorderStyle { get; set; }
public:
virtual property BorderStyle BorderStyle {
    BorderStyle get ();
    void set (BorderStyle value);
}
/** @property */
public BorderStyle get_BorderStyle ()

/** @property */
public void set_BorderStyle (BorderStyle value)
public function get BorderStyle () : BorderStyle

public function set BorderStyle (value : BorderStyle)
適用できません。

プロパティ値

BorderStyle 列挙値の 1 つ。既定値は NotSet です。

解説

BorderStyle プロパティを使用して、Web サーバー コントロールの境界線スタイルを指定します。このプロパティは、BorderStyle 列挙値の 1 つを使用して設定します。有効値の一覧を次の表に示します。

境界線スタイル

説明

NotSet

境界線スタイルは設定されていません。

None

境界線なし。

Dotted

点線の境界線。

Dashed

破線の境界線。

Solid

実線の境界線。

Double

二重実線の境界線。

Groove

境界線をくぼみ表示にするための下降側の境界線。

Ridge

境界線を浮き出して表示するための上昇側の境界線。

Inset

コントロールをくぼんで表示するためのくぼみ表示の境界線。

Outset

コントロールを浮き出して表示するためのアウトセット境界線。

メモメモ :

このプロパティは、どの Web サーバー コントロールについても、Microsoft Internet Explorer 4 より前のブラウザには表示されません。HTML 3.2 にはこれと等価のプロパティはありません。

使用例

WebControl 基本クラスから継承された、Table コントロールの BorderStyle プロパティの設定方法の例を次に示します。

<%@ 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>
<%@ 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="JScript" %>
<!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. -->

...

<%@ 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
            ' 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)
            ' 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)
        ' 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)
    End Sub

    ' This method handles the selectedIndexChanged event for boderStyleList.
    Public Sub ChangeBorderStyle(sender As Object, e As System.EventArgs)
        ' 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)
    End Sub

    ' This method handles the SelectedIndexChanged event for borderWidthList.
    Public Sub ChangeBorderWidth(sender As Object, e As System.EventArgs)
        ' 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)
    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>
<!-- 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)
        {
            // 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);
            // 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)
    {
        // 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);
    }

    // This method handles the selectedIndexChanged event for boderStyleList.
    public void ChangeBorderStyle(object sender, System.EventArgs e)
    {
        // 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);
    }

    // This method handles the SelectedIndexChanged event for borderWidthList.
    public void ChangeBorderWidth(object sender, System.EventArgs e)
    {
        // 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);
    }
    </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>
<!-- 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="VJ#" 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 (!get_Page().get_IsPostBack()) {
            // Create a ListItemCollection and add names of colors.
            ListItemCollection colors = new ListItemCollection();
            colors.Add(Color.get_Black().get_Name());
            colors.Add(Color.get_Blue().get_Name());
            colors.Add(Color.get_Green().get_Name());
            colors.Add(Color.get_Orange().get_Name());
            colors.Add(Color.get_Purple().get_Name());
            colors.Add(Color.get_Red().get_Name());
            colors.Add(Color.get_White().get_Name());
            colors.Add(Color.get_Yellow().get_Name());
            
            // Bind the colors collection to the borderColorList.
            borderColorList.set_DataSource(colors);
            borderColorList.DataBind();
            // Create a ListItemCollection and the add names of 
            // the BorderStyle enumeration values.
            ListItemCollection styles = new ListItemCollection();
            for (int iCtr = 0; iCtr < System.Enum.GetNames(
                    BorderStyle.class.ToType()).length; iCtr++) {
                String s = (String)System.Enum.GetNames
                    (BorderStyle.class.ToType()).get_Item(iCtr);
                styles.Add(s);
            }
            // Bind the styles collection to the borderStyleList.
            borderStyleList.set_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(System.Convert.ToString(i) + "px");
            }

            // Bind the widths collection to the borderWidthList.
            borderWidthList.set_DataSource(widths);
            borderWidthList.DataBind();
        }
    }//Page_Load

    // This method handles the SelectedIndexChanged event
    // for borderColorList.
    public void ChangeBorderColor(Object sender, System.EventArgs e)
    {
        // Convert the color name string to an object of type Color, 
        // and set the Color as the new border color for Label1.
        Label1.set_BorderColor(Color.FromName
            (borderColorList.get_SelectedItem().get_Text()));
    }//ChangeBorderColor

    // This method handles the selectedIndexChanged event
    // for boderStyleList.
    public void ChangeBorderStyle(Object sender, System.EventArgs e)
    {
        // Convert the style name string to a BorderStyle
        // enumeration value,and set the BorderStyle as the
        // new border style for Label1.
        Label1.set_BorderStyle((BorderStyle)System.Enum.Parse
            (BorderStyle.class.ToType(),
            borderStyleList.get_SelectedItem().get_Text()));
    }//ChangeBorderStyle

    // This method handles the SelectedIndexChanged event
    // for borderWidthList.
    public void ChangeBorderWidth(Object sender, System.EventArgs e)
    {
        // Convert the border width string to a object of type Unit,
        // and set the Unit as the new border width for Label1.
        Label1.set_BorderWidth(Unit.Parse
            (borderWidthList.get_SelectedItem().get_Text()));
    }//ChangeBorderWidth
    </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>

プラットフォーム

Windows 98,Windows Server 2000 SP4,Windows CE,Windows Millennium Edition,Windows Mobile for Pocket PC,Windows Mobile for Smartphone,Windows Server 2003,Windows XP Media Center Edition,Windows XP Professional x64 Edition,Windows XP SP2,Windows XP Starter Edition

Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。

バージョン情報

.NET Framework

サポート対象 : 3.0,2.0,1.1,1.0

参照

関連項目

WebControl クラス
WebControl メンバ
System.Web.UI.WebControls 名前空間
Style
BorderStyle

その他の技術情報

ASP.NET Web サーバー コントロールとブラウザの機能
Web サーバー コントロール構文
ASP.NET カスタム サーバー コントロールの開発