ScrollBar.Maximum プロパティ

定義

スクロール可能な範囲の上限値を取得または設定します。Gets or sets the upper limit of values of the scrollable range.

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

プロパティ値

数値を指定します。A numeric value. 既定値は 100 です。The default value is 100.

次の例では、@no__t 0 が作成されていることを前提としています。 FormPictureBox を追加し、水平方向の HScrollBar と垂直 VScrollBarPictureBox に追加しました。The following example assumes that you have created a Form, added a PictureBox to the Form, and added a horizontal HScrollBar and a vertical VScrollBar to the PictureBox. このコード例は、ScrollBar クラスの概要について提供されている大規模な例の一部です。This code example is part of a larger example provided for the ScrollBar class overview.

この例では、Maximum プロパティは、@no__t のサイズと、スクロールバーが @no__t 表示されている場合は scrollbar のサイズを加算した値に設定されます。In this example, the Maximum property is set to the size of the Image plus the size of the scrollbar if it is visible plus an adjustment factor of the size of the LargeChange property.

この例を実行するには、System.Drawing および System.Windows.Forms の名前空間への参照を追加する必要があります。You must add references to the System.Drawing and System.Windows.Forms namespaces to run this example.

注意

Visual Studio でこの例を実行する方法については、@no__t を参照してください。Visual Studio @ no__t を使用して、完全な Windows フォームコード例をコンパイルして実行します。For instructions about how to run this example in Visual Studio, see 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

注釈

ピクセルサイズまたは表示される行数に応じて、スクロールバーの親のサイズに合わせて @no__t 0 プロパティを動的に調整することを検討してください。You might consider adjusting the Maximum property dynamically to match the size of the scroll bar's parent in proportion to pixel size or to the number of rows or lines displayed.

最大値には、プログラムでしか到達できません。The maximum value can only be reached programmatically. スクロールバーの値は、実行時のユーザー操作によって最大値に達してはなりません。The value of a scroll bar cannot reach its maximum value through user interaction at run time. ユーザーとの対話によって到達できる最大値は、1に加えて Maximum プロパティ値から LargeChange プロパティ値を引いた値です。The maximum value that can be reached through user interaction is equal to 1 plus the Maximum property value minus the LargeChange property value. 必要に応じて、Maximum プロパティをオブジェクトのサイズに設定して、1の用語に対してアカウントを作成できます。If necessary, you can set the Maximum property to the size of the object -1 to account for the term of 1.

適用対象

こちらもご覧ください