ScrollBar.Maximum Proprietà

Definizione

Ottiene o imposta il limite superiore dei valori dell'intervallo di scorrimento.

public:
 property int Maximum { int get(); void set(int value); };
public int Maximum { get; set; }
member this.Maximum : int with get, set
Public Property Maximum As Integer

Valore della proprietà

Int32

Valore numerico. Il valore predefinito è 100.

Esempio

Nell'esempio seguente si presuppone che sia stato creato un Formoggetto , aggiunto a FormPictureBox e aggiunto un oggetto orizzontale HScrollBar e un verticale VScrollBar all'oggetto PictureBox. Questo esempio di codice fa parte di un esempio più ampio fornito per la panoramica della ScrollBar classe.

In questo esempio, la Maximum proprietà viene impostata sulle dimensioni del Image segno più la dimensione della barra di scorrimento se è visibile più un fattore di regolazione delle dimensioni della LargeChange proprietà.

Per eseguire questo esempio, è necessario aggiungere riferimenti agli System.Drawing spazi dei nomi e System.Windows.Forms .

Nota

Per istruzioni su come eseguire questo esempio in Visual Studio, vedere Procedura: Compilare ed eseguire un esempio di codice completo Windows Forms usando Visual Studio.

public void SetScrollBarValues()
{
    //Set the following scrollbar properties:

    //Minimum: Set to 0

    //SmallChange and LargeChange: Per UI guidelines, these must be set
    //    relative to the size of the view that the user sees, not to
    //    the total size including the unseen part.  In this example,
    //    these must be set relative to the picture box, not to the image.

    //Maximum: Calculate in steps:
    //Step 1: The maximum to scroll is the size of the unseen part.
    //Step 2: Add the size of visible scrollbars if necessary.
    //Step 3: Add an adjustment factor of ScrollBar.LargeChange.

    //Configure the horizontal scrollbar
    //---------------------------------------------
    if (this.hScrollBar1.Visible)
    {
        this.hScrollBar1.Minimum = 0;
        this.hScrollBar1.SmallChange = this.pictureBox1.Width / 20;
        this.hScrollBar1.LargeChange = this.pictureBox1.Width / 10;

        this.hScrollBar1.Maximum = this.pictureBox1.Image.Size.Width - pictureBox1.ClientSize.Width;  //step 1

        if (this.vScrollBar1.Visible) //step 2
        {
            this.hScrollBar1.Maximum += this.vScrollBar1.Width;
        }

        this.hScrollBar1.Maximum += this.hScrollBar1.LargeChange; //step 3
    }

    //Configure the vertical scrollbar
    //---------------------------------------------
    if (this.vScrollBar1.Visible)
    {
        this.vScrollBar1.Minimum = 0;
        this.vScrollBar1.SmallChange = this.pictureBox1.Height / 20;
        this.vScrollBar1.LargeChange = this.pictureBox1.Height / 10;

        this.vScrollBar1.Maximum = this.pictureBox1.Image.Size.Height - pictureBox1.ClientSize.Height; //step 1

        if (this.hScrollBar1.Visible) //step 2
        {
            this.vScrollBar1.Maximum += this.hScrollBar1.Height;
        }

        this.vScrollBar1.Maximum += this.vScrollBar1.LargeChange; //step 3
    }
}
Public Sub SetScrollBarValues()

    'Set the following scrollbar properties:

    'Minimum: Set to 0

    'SmallChange and LargeChange: Per UI guidelines, these must be set
    '    relative to the size of the view that the user sees, not to
    '    the total size including the unseen part.  In this example,
    '    these must be set relative to the picture box, not to the image.

    'Maximum: Calculate in steps:
    'Step 1: The maximum to scroll is the size of the unseen part.
    'Step 2: Add the size of visible scrollbars if necessary.
    'Step 3: Add an adjustment factor of ScrollBar.LargeChange.


    'Configure the horizontal scrollbar
    '---------------------------------------------
    If (Me.hScrollBar1.Visible) Then

        Me.hScrollBar1.Minimum = 0
        Me.hScrollBar1.SmallChange = CInt(Me.pictureBox1.Width / 20)
        Me.hScrollBar1.LargeChange = CInt(Me.pictureBox1.Width / 10)

        Me.hScrollBar1.Maximum = Me.pictureBox1.Image.Size.Width - pictureBox1.ClientSize.Width  'step 1

        If (Me.vScrollBar1.Visible) Then 'step 2

            Me.hScrollBar1.Maximum += Me.vScrollBar1.Width
        End If

        Me.hScrollBar1.Maximum += Me.hScrollBar1.LargeChange 'step 3
    End If

    'Configure the vertical scrollbar
    '---------------------------------------------
    If (Me.vScrollBar1.Visible) Then

        Me.vScrollBar1.Minimum = 0
        Me.vScrollBar1.SmallChange = CInt(Me.pictureBox1.Height / 20)
        Me.vScrollBar1.LargeChange = CInt(Me.pictureBox1.Height / 10)

        Me.vScrollBar1.Maximum = Me.pictureBox1.Image.Size.Height - pictureBox1.ClientSize.Height 'step 1

        If (Me.hScrollBar1.Visible) Then 'step 2

            Me.vScrollBar1.Maximum += Me.hScrollBar1.Height
        End If

        Me.vScrollBar1.Maximum += Me.vScrollBar1.LargeChange 'step 3
    End If
 End Sub

Commenti

È possibile modificare la Maximum proprietà in modo dinamico in modo che corrisponda alle dimensioni dell'elemento padre della barra di scorrimento in proporzione alle dimensioni del pixel o al numero di righe o righe visualizzate.

Il valore massimo può essere raggiunto solo a livello di codice. Il valore di una barra di scorrimento non può raggiungere il valore massimo tramite l'interazione dell'utente in fase di esecuzione. Il valore massimo che può essere raggiunto tramite l'interazione dell'utente è uguale a 1 più il valore della Maximum proprietà meno il valore della LargeChange proprietà. Se necessario, è possibile impostare la Maximum proprietà sulla dimensione dell'oggetto -1 per tenere conto del termine di 1.

Si applica a

Vedi anche