ScrollBars Énumération

Définition

Spécifie la visibilité et la position des barres de défilement dans un contrôle Panel.

Cette énumération prend en charge une combinaison au niveau du bit de ses valeurs membres.

public enum class ScrollBars
[System.Flags]
public enum ScrollBars
[<System.Flags>]
type ScrollBars = 
Public Enum ScrollBars
Héritage
ScrollBars
Attributs

Champs

Auto 4

Si nécessaire, les barres de défilement horizontales, verticales, ou les deux, sont affichées. Sinon, aucune barre de défilement n'est visible.

Both 3

Affiche à la fois une barre de défilement horizontale et une barre de défilement verticale.

Horizontal 1

Affiche uniquement une barre de défilement horizontale.

None 0

N'affiche aucune barre de défilement.

Vertical 2

Affiche uniquement une barre de défilement verticale.

Exemples

L’exemple de code suivant montre comment définir de manière déclarative la ScrollBars propriété Autosur . Le panneau contient une table, dont le contenu entier dépasse la taille du panneau. Cela entraîne l’affichage automatique des barres de défilement verticales et horizontales lorsque le panneau est rendu. L’utilisateur peut ensuite faire défiler pour afficher toutes les données de la table.

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

L’exemple de code suivant illustre les valeurs d’énumération ScrollBars . Un ListBox contrôle est rempli avec les valeurs d’énumération ScrollBars . Les barres de défilement affichées dans le panneau changent, en fonction de la valeur que l’utilisateur sélectionne dans la zone de liste.

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

Remarques

L’énumération ScrollBars représente la visibilité et la position des barres de défilement dans un Panel contrôle. La ScrollBars propriété utilise ces valeurs d’énumération pour spécifier le type de barres de défilement à afficher dans un Panel contrôle. La valeur par défaut de la ScrollBars propriété est , indiquant qu’aucune barre de défilement n’est Noneaffichée.

Si vous spécifiez pour la ScrollBars propriété, les barres de défilement s’affichent Auto automatiquement lorsque la taille du contenu dans un Panel contrôle dépasse la taille du Panel contrôle. Par exemple, si un Panel contrôle contient une table et que le panneau n’est pas suffisamment large pour afficher toutes les lignes de la table, une barre de défilement verticale est affichée. Si la taille du tableau dépasse la hauteur et la largeur du panneau, les barres de défilement verticales et horizontales sont affichées.

S’applique à

Voir aussi