Este tema aún no ha recibido ninguna valoración - Valorar este tema

WebControl.BorderWidth (Propiedad)

Obtiene o establece el ancho del borde del control de servidor Web.

Espacio de nombres: System.Web.UI.WebControls
Ensamblado: System.Web (en system.web.dll)

public virtual Unit BorderWidth { get; set; }
/** @property */
public Unit get_BorderWidth ()

/** @property */
public void set_BorderWidth (Unit value)

public function get BorderWidth () : Unit

public function set BorderWidth (value : Unit)

No aplicable.

Valor de propiedad

Objeto Unit que representa el ancho del borde de un control de servidor Web. El valor predeterminado es Empty, que indica que no se ha establecido esta propiedad.
Tipo de excepción Condición

ArgumentException

El ancho de borde especificado es un valor negativo.

La propiedad BorderWidth se utiliza para especificar el ancho de borde de un control.

NotaNota:

Esta propiedad no funciona con todos los controles de servidor Web. Sólo se aplica a los controles que se muestran en forma de tabla; como por ejemplo Table y DataGrid.

Esta propiedad se establece mediante un objeto Unit. Si la propiedad Value de la Unit contiene un número negativo, se produce una excepción.

NotaNota:

En el caso de los exploradores anteriores a la versión 5 de Microsoft Internet Explorer, el ancho del borde sólo puede expresarse en píxeles. La versión 5 de Microsoft Internet Explorer y las versiones posteriores admiten todos los tipos de unidades. Consulte los detalles en el control específico.

En el ejemplo siguiente se muestra cómo establecer la propiedad BorderWidth del control Table, que se hereda de la clase base 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>Table Property</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h3>Property of a Table Web Control</h3>
 
        <asp:Table id="Table1" runat="server"
            CellPadding = "10" 
            CellSpacing="0"
            GridLines="Both"
            BorderColor="Red"
            BorderWidth="3">

            <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>

NotaNota:

El siguiente ejemplo de código utiliza un modelo de código de un solo archivo y puede que no funcione correctamente si se copia directamente en un archivo de código subyacente. Se debe copiar este código de ejemplo en un archivo de texto vacío con una extensión .aspx. Para obtener más información sobre el modelo de código de los formularios Web Forms, vea Modelo de código de las páginas Web ASP.NET.

<!-- 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 2000 Service Pack 4, Windows CE, Windows Millennium, Windows Mobile para Pocket PC, Windows Mobile para Smartphone, Windows Server 2003, Windows XP Media Center, Windows XP Professional x64, Windows XP SP2, Windows XP Starter

Microsoft .NET Framework 3.0 es compatible con Windows Vista, Microsoft Windows XP SP2 y Windows Server 2003 SP1.

.NET Framework

Compatible con: 3.0, 2.0, 1.1, 1.0
¿Le ha resultado útil?
(Caracteres restantes: 1500)