ScrollBar.Maximum 属性

定义

获取或设置可滚动范围的上限值。

C#
public int Maximum { get; set; }

属性值

Int32

一个数值。 默认值为 100。

示例

以下示例假定你已创建一个、已向该Form对象添加一个FormPictureBox、添加水平HScrollBar和垂直VScrollBarPictureBox值。 此代码示例是为类概述提供的大型示例的 ScrollBar 一部分。

在此示例中,如果该属性可见,则 Maximum 此属性设置为滚动条的大小 Image 加上属性大小的 LargeChange 调整因子。

必须添加对命名空间的System.DrawingSystem.Windows.Forms引用才能运行此示例。

备注

有关如何在Visual Studio中运行此示例的说明,请参阅如何:使用 Visual Studio 编译和运行完整的Windows 窗体代码示例

C#
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
    }
}

注解

可以考虑动态调整 Maximum 属性,以匹配滚动条的父级的大小,以按像素大小或显示的行数或行数。

只能以编程方式访问最大值。 滚动条的值无法在运行时通过用户交互达到其最大值。 可以通过用户交互达到的最大值等于 1,属性值 Maximum 减去 LargeChange 属性值。 如有必要,可以将属性设置为 Maximum 对象 -1 的大小,以考虑术语 1。

适用于

产品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Windows Desktop 3.0, 3.1, 5, 6, 7

另请参阅