ScrollBar.SmallChange 属性

定义

获取或设置小距离移动滚动框时,在 Value 属性中加上或减去的值。

C#
public int SmallChange { get; set; }

属性值

Int32

一个数值。 默认值为 1。

例外

所分配的值小于 0。

示例

以下示例假定你已创建一个、已向其中添加一个FormPictureBox、添加一个水平HScrollBar和垂直PictureBoxVScrollBarForm 此代码示例是类概述提供的较大示例的 ScrollBar 一部分。

在此示例中,属性 SmallChange 相对于大小设置 PictureBox

必须添加对 System.Drawing 命名空间 System.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
    }
}

注解

当用户按下其中一个箭头键或单击其中一个滚动条按钮时,该 Value 属性会根据属性中 SmallChange 设置的值更改。

用户界面指南建议, SmallChange 相对于用户看到的视图的大小设置属性和 LargeChange 属性,而不是总大小(包括看不到的部分)。 例如,如果有一个显示大型图像的滚动条的图片框, SmallChange 则应相对于图片框的大小设置属性 LargeChange ,而不是图像的大小。

适用于

产品 版本
.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

另请参阅