ScrollBar.Maximum プロパティ

定義

スクロール可能な範囲の上限値を取得または設定します。

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

プロパティ値

Int32

数値を指定します。 既定値は 100 です。

次の例では、a を作成Formし、次の例に a をForm追加PictureBoxし、水平HScrollBarと垂直VScrollBarPictureBoxを追加していることを前提としています。 このコード例は、クラスの概要に関して提供されるより大きな例の ScrollBar 一部です。

この例では、 Maximum 表示されている場合、プロパティはスクロール バーの Image サイズとプロパティのサイズの調整係数を加えたサイズに LargeChange 設定されます。

この例を実行するには、 System.Drawing and System.Windows.Forms 名前空間への参照を追加する必要があります。

注意

Visual Studioでこの例を実行する方法については、「方法: Visual Studioを使用して完全なWindows フォームコード例をコンパイルして実行する」を参照してください。

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

注釈

ピクセル サイズまたは表示される行数または行数に比例して、スクロール バーの親のサイズに合わせてプロパティを動的に調整 Maximum することを検討してください。

最大値にはプログラムでのみ到達できます。 スクロール バーの値は、実行時のユーザー操作によって最大値に達することはできません。 ユーザーの操作によって到達できる最大値は、1 とプロパティ値からプロパティ値を Maximum 引いた値に LargeChange 等しくなります。 必要に応じて、プロパティを Maximum オブジェクト -1 のサイズに設定して、1 という用語を考慮することができます。

適用対象

こちらもご覧ください