Freigeben über


ScrollBar.Maximum Eigenschaft

Definition

Ruft die obere Grenze der Werte des bildlauffähigen Bereichs ab oder legt diese fest.

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

Eigenschaftswert

Ein numerischer Wert. Der Standardwert ist 100.

Beispiele

Im folgenden Beispiel wird davon ausgegangen, dass Sie einen Form, PictureBox dem Formhinzugefügt und eine horizontale HScrollBar und eine vertikale zu VScrollBar der PictureBoxhinzugefügt haben. Dieses Codebeispiel ist Teil eines größeren Beispiels, das für die ScrollBar Klassenübersicht bereitgestellt wird.

In diesem Beispiel wird die Maximum Eigenschaft auf die Größe des Image Pluszeichens der Bildlaufleiste festgelegt, wenn sie sichtbar ist, und einen Anpassungsfaktor der Größe der LargeChange Eigenschaft.

Sie müssen Verweise auf die System.Drawing Und System.Windows.Forms Namespaces hinzufügen, um dieses Beispiel auszuführen.

Hinweis

Anweisungen zum Ausführen dieses Beispiels in Visual Studio finden Sie unter How to: Compile and Run a Complete Windows Forms Code Example Using 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

Hinweise

Möglicherweise können Sie die Maximum Eigenschaft dynamisch anpassen, um die Größe des übergeordneten Elements der Bildlaufleiste proportional zur Pixelgröße oder zur Anzahl der angezeigten Zeilen oder Zeilen anzupassen.

Der Maximalwert kann nur programmgesteuert erreicht werden. Der Wert einer Bildlaufleiste kann den Maximalwert nicht über die Benutzerinteraktion zur Laufzeit erreichen. Der maximale Wert, der über benutzerinteraktion erreicht werden kann, ist gleich 1 plus dem Maximum Eigenschaftswert minus dem LargeChange Eigenschaftswert. Bei Bedarf können Sie die Maximum Eigenschaft auf die Größe des Objekts -1 festlegen, um den Ausdruck von 1 zu berücksichtigen.

Gilt für:

Weitere Informationen