Panel.ScrollBars Propiedad

Definición

Obtiene o establece la visibilidad y la posición de las barras de desplazamiento de un control Panel.

public:
 virtual property System::Web::UI::WebControls::ScrollBars ScrollBars { System::Web::UI::WebControls::ScrollBars get(); void set(System::Web::UI::WebControls::ScrollBars value); };
public virtual System.Web.UI.WebControls.ScrollBars ScrollBars { get; set; }
member this.ScrollBars : System.Web.UI.WebControls.ScrollBars with get, set
Public Overridable Property ScrollBars As ScrollBars

Valor de propiedad

Uno de los valores de enumeración de ScrollBars. De manera predeterminada, es None.

Ejemplos

En el ejemplo de código siguiente se muestra cómo establecer mediante declaración la ScrollBars propiedad en Auto. El panel contiene una tabla, todo el contenido del cual supera el tamaño del panel. Esto hace que las barras de desplazamiento vertical y horizontal se muestren automáticamente cuando se representa el panel. A continuación, el usuario puede desplazarse para ver todos los datos de la tabla.

Nota

En el ejemplo de código siguiente se usa el modelo de código de un solo archivo y es posible que no funcione correctamente si se copia directamente en un archivo de código subyacente. Este ejemplo de código debe copiarse en un archivo de texto vacío que tenga una extensión .aspx. Para obtener más información sobre el modelo de código de Web Forms, consulte ASP.NET Web Forms Modelo de código de página.

<%@ 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">
    private void Page_Load(object sender, EventArgs e)
    {
        // Add more rows and columns to the table than can
        // be displayed in the panel area.
        // Scroll bars will be required to view all the data.

        // Add rows and columns to the table.
        for (int rowNum = 0; rowNum < 51; rowNum++)
        {
            TableRow tempRow = new TableRow();
            for (int cellNum = 0; cellNum < 11; cellNum++)
            {
                TableCell tempCell = new TableCell();
                tempCell.Text = 
                    String.Format("({0}, {1})", rowNum, cellNum);
                tempRow.Cells.Add(tempCell);
            }
            Table1.Rows.Add(tempRow);
        }
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head2" runat="server">
    <title>Panel Scrollbars - C# Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    <h3>Panel.ScrollBars Property Example</h3>        

    <asp:Panel ID="Panel1" runat="Server"
      Height="300px" Width="400px"
      BackColor="Aqua" ScrollBars="Auto">

      <asp:Table ID="Table1" runat="Server"></asp:Table>  

    </asp:Panel>         

    </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">
    Private Sub Page_Load(ByVal sender As Object, _
        ByVal e As System.EventArgs)

        ' Add more rows and columns to the table than can
        ' be displayed in the panel area.
        ' Scroll bars will be required to view all the data.

        ' Add rows and columns to the table.
        Dim rowNum As Integer
        For rowNum = 0 To 50
            Dim tempRow As New TableRow
            Dim cellNum As Integer
            For cellNum = 0 To 10
                Dim tempCell As New TableCell
                tempCell.Text = _
                    String.Format("({0}, {1})", rowNum, cellNum)
                tempRow.Cells.Add(tempCell)
            Next
            Table1.Rows.Add(tempRow)
        Next
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head2" runat="server">
    <title>Panel Scrollbars - VB.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    <h3>Panel.ScrollBars Property Example</h3>        

    <asp:Panel ID="Panel1" runat="Server"
      Height="300px" Width="400px"
      BackColor="Aqua" ScrollBars="Auto">

      <asp:Table ID="Table1" runat="Server"></asp:Table>  

    </asp:Panel>         

    </div>
    </form>
</body>
</html>

En el ejemplo de código siguiente se muestra cómo establecer mediante programación la ScrollBars propiedad . Un ListBox control se rellena con los ScrollBars valores de enumeración. Las barras de desplazamiento que se muestran en el panel cambian, en función del valor que el usuario selecciona en el cuadro de lista.

Nota

En el ejemplo de código siguiente se usa el modelo de código de un solo archivo y es posible que no funcione correctamente si se copia directamente en un archivo de código subyacente. Este ejemplo de código debe copiarse en un archivo de texto vacío que tenga una extensión .aspx. Para obtener más información sobre el modelo de código de Web Forms, consulte ASP.NET Web Forms Modelo de código de página.

<%@ 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">
    private void Page_Load(object sender, EventArgs e)
    {
        // Add more rows and columns to the table than can
        // be displayed in the panel area.
        // Scroll bars will be required to view all the data.

        // Add rows and columns to the table.
        for (int rowNum = 0; rowNum < 51; rowNum++)
        {
            TableRow tempRow = new TableRow();
            for (int cellNum = 0; cellNum < 11; cellNum++)
            {
                TableCell tempCell = new TableCell();
                tempCell.Text = 
                    String.Format("({0}, {1})", rowNum, cellNum);
                tempRow.Cells.Add(tempCell);
            }
            Table1.Rows.Add(tempRow);
        }
    }

    private void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        // Determine which list item was clicked.
        // Display the selected scroll bars in the panel.
        switch (ListBox1.SelectedIndex)
        {
            case 0:
                Panel1.ScrollBars = ScrollBars.None;
                break;
            case 1:
                Panel1.ScrollBars = ScrollBars.Horizontal;
                break;
            case 2:
                Panel1.ScrollBars = ScrollBars.Vertical;
                break;
            case 3:
                Panel1.ScrollBars = ScrollBars.Both;
                break;
            case 4:
                Panel1.ScrollBars = ScrollBars.Auto;
                break;
            default:
                throw new Exception("Select a valid list item.");
        }
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head2" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    <h3>Panel.ScrollBars Property Example</h3>

    <h4>Select the scrollbars to display in the panel.</h4>
    <asp:ListBox ID="ListBox1" runat="Server"
      Rows="5" AutoPostBack="True"
      SelectionMode="Single"
      OnSelectedIndexChanged="ListBox1_SelectedIndexChanged">
      <asp:ListItem>None</asp:ListItem>
      <asp:ListItem>Horizontal</asp:ListItem> 
      <asp:ListItem>Vertical</asp:ListItem>
      <asp:ListItem>Both</asp:ListItem> 
      <asp:ListItem>Auto</asp:ListItem>              
    </asp:ListBox>

    <hr />              

    <asp:Panel ID="Panel1" runat="Server"
      Height="300px" Width="400px" BackColor="Aqua">
      <asp:Table ID="Table1" runat="Server" />
    </asp:Panel>           
         
    </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">
    Private Sub Page_Load(ByVal sender As Object, _
        ByVal e As System.EventArgs)

        ' Add more rows and columns to the table than can
        ' be displayed in the panel area.
        ' Scroll bars will be required to view all the data.

        ' Add rows and columns to the table.
        Dim i As Integer
        For i = 0 To 50
            Dim tempRow As New TableRow
            Dim j As Integer
            For j = 0 To 10
                Dim tempCell As New TableCell
                tempCell.Text = "(" & i & "," & j & ")"
                tempRow.Cells.Add(tempCell)
            Next j
            Table1.Rows.Add(tempRow)
        Next i
    End Sub

    Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, _
        ByVal e As EventArgs)

        ' Determine which list item was clicked.
        ' Display the selected scroll bars in the panel.
        Select Case (ListBox1.SelectedIndex)
            Case 0
                Panel1.ScrollBars = ScrollBars.None
            Case 1
                Panel1.ScrollBars = ScrollBars.Horizontal
            Case 2
                Panel1.ScrollBars = ScrollBars.Vertical
            Case 3
                Panel1.ScrollBars = ScrollBars.Both
            Case 4
                Panel1.ScrollBars = ScrollBars.Auto
            Case Else
                Throw New Exception("Select a valid list item.")
        End Select

    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head2" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    <h3>Panel.ScrollBars Property Example</h3>

    <h4>Select the scrollbars to display in the panel.</h4>
    <asp:ListBox ID="ListBox1" runat="Server"
      Rows="5" AutoPostBack="True" SelectionMode="Single"
      OnSelectedIndexChanged="ListBox1_SelectedIndexChanged">
      <asp:ListItem>None</asp:ListItem>
      <asp:ListItem>Horizontal</asp:ListItem> 
      <asp:ListItem>Vertical</asp:ListItem>
      <asp:ListItem>Both</asp:ListItem> 
      <asp:ListItem>Auto</asp:ListItem>              
    </asp:ListBox>

    <hr />              

    <asp:Panel ID="Panel1" runat="Server"
      Height="300px" Width="400px" BackColor="Aqua">
      <asp:Table ID="Table1" runat="Server" />
    </asp:Panel>           
         
    </div>
    </form>
</body>
</html>

Comentarios

Utilice la ScrollBars propiedad para especificar la visibilidad y la posición de las barras de desplazamiento en un Panel control . Esta propiedad se establece mediante uno de los ScrollBars valores de enumeración. En la tabla siguiente se enumeran los valores posibles.

Value Descripción
None No se muestra ninguna barra de desplazamiento.
Horizontal Solo se muestra una barra de desplazamiento horizontal.
Vertical Solo se muestra una barra de desplazamiento vertical.
Both Se muestran las barras de desplazamiento horizontal y vertical.
Auto Si es necesario, se muestran las barras de desplazamiento horizontales, verticales o ambas. En caso contrario, no se muestran barras de desplazamiento.

Si especifica Auto para la ScrollBars propiedad , las barras de desplazamiento se muestran automáticamente cuando el tamaño del contenido de un Panel control supera el tamaño del Panel propio control. Por ejemplo, si un Panel control contiene una tabla y el panel no es lo suficientemente ancho como para mostrar todas las filas de la tabla, se muestra una barra de desplazamiento vertical. Si el tamaño de la tabla supera el alto y el ancho del panel, se muestran las barras de desplazamiento vertical y horizontal.

Nota

Esta propiedad solo se admite en exploradores que admiten HTML 4.0 o posterior.

Se aplica a

Consulte también