ScrollBar.SmallChange Property

Gets or sets the value to be added to or subtracted from the Value property when the scroll box is moved a small distance.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public int SmallChange { get; set; }
/** @property */
public int get_SmallChange ()

/** @property */
public void set_SmallChange (int value)

public function get SmallChange () : int

public function set SmallChange (value : int)

Property Value

A numeric value. The default value is 1.

Exception typeCondition

ArgumentOutOfRangeException

The assigned value is less than 0.

When the user presses one of the arrow keys or clicks one of the scroll bar buttons, the Value property changes according to the value set in the SmallChange property.

You might consider setting the SmallChange value to a percentage of the Height (for a vertically oriented scroll bar) or Width (for a horizontally oriented scroll bar) values. This keeps the distance your scroll bar moves in proportion to its size.

The following code example uses the derived classes VScrollBar and HScrollBar, and sets some of their common properties. Their Maximum properties are set equal to the Height or Width of the Image assigned to their parent, a PictureBox. The LargeChange property is set equal to the size of the picture box (with the height or width of the scroll bars subtracted). The SmallChange property is set equal to the LargeChange property value divided by 5. Lastly, the Value property values for both of the scroll bars are set to 0. The result is vertical and horizontal scroll bars displayed on a picture box that displays the upper-left corner of the Image. The scroll bars will not scroll past the end of the image, and when a LargeChange scroll happens, the image will only move the same distance as the area displayed in the picture box. It takes five SmallChange scrolls to move the same distance as one LargeChange scroll. This code assumes a PictureBox, HScrollBar, VScrollBar, and Image have all been created on a Form. It also assumes that a reference to the System.Drawing namespace has been added. For additional code that can extend this example, see the ScrollBar class overview.

public void SetScrollBarValues() 
{
   // Set the Maximum, Minimum, LargeChange and SmallChange properties.
   this.vScrollBar1.Minimum = 0;
   this.hScrollBar1.Minimum = 0;
   // If the offset does not make the Maximum less than zero, set its value. 
   if( (this.pictureBox1.Image.Size.Width - pictureBox1.ClientSize.Width) > 0)
   {
      this.hScrollBar1.Maximum = this.pictureBox1.Image.Size.Width - pictureBox1.ClientSize.Width;
   }
   /* If the VScrollBar is visible, adjust the Maximum of the 
      HSCrollBar to account for the width of the VScrollBar. */
   if(this.vScrollBar1.Visible)
   {
      this.hScrollBar1.Maximum += this.vScrollBar1.Width;
   }
   this.hScrollBar1.LargeChange = this.hScrollBar1.Maximum / 10;
   this.hScrollBar1.SmallChange = this.hScrollBar1.Maximum / 20;
   // Adjust the Maximum value to make the raw Maximum value attainable by user interaction.
   this.hScrollBar1.Maximum += this.hScrollBar1.LargeChange;
     
   // If the offset does not make the Maximum less than zero, set its value.    
   if( (this.pictureBox1.Image.Size.Height - pictureBox1.ClientSize.Height) > 0)
   {
      this.vScrollBar1.Maximum = this.pictureBox1.Image.Size.Height - pictureBox1.ClientSize.Height;
   }
   /* If the HScrollBar is visible, adjust the Maximum of the 
      VSCrollBar to account for the width of the HScrollBar.*/
   if(this.hScrollBar1.Visible)
   {
      this.vScrollBar1.Maximum += this.hScrollBar1.Height;
   }
   this.vScrollBar1.LargeChange = this.vScrollBar1.Maximum / 10;
   this.vScrollBar1.SmallChange = this.vScrollBar1.Maximum / 20;
   // Adjust the Maximum value to make the raw Maximum value attainable by user interaction.
   this.vScrollBar1.Maximum += this.vScrollBar1.LargeChange;
}

public void SetScrollBarValues()
{
    // Set the Maximum, Minimum, LargeChange and SmallChange properties.
    this.vScrollBar1.set_Minimum(0);
    this.hScrollBar1.set_Minimum(0);

    // If the offset does not make the Maximum less than zero, 
    // set its value. 
    if (this.pictureBox1.get_Image().get_Size().get_Width() 
        - pictureBox1.get_ClientSize().get_Width() > 0) {
            this.hScrollBar1.set_Maximum(
                this.pictureBox1.get_Image().get_Size().get_Width() 
                - pictureBox1.get_ClientSize().get_Width());
    }

    /* If the VScrollBar is visible, adjust the Maximum of the 
       HSCrollBar to account for the width of the VScrollBar. 
     */
    if (this.vScrollBar1.get_Visible()) {
        this.hScrollBar1.set_Maximum(
            this.hScrollBar1.get_Maximum() + this.vScrollBar1.get_Width());
    }

    this.hScrollBar1.set_LargeChange(this.hScrollBar1.get_Maximum() / 10);
    this.hScrollBar1.set_SmallChange(this.hScrollBar1.get_Maximum() / 20);

    // Adjust the Maximum value to make the raw Maximum value attainable 
    // by user interaction.
    this.hScrollBar1.set_Maximum(
        this.hScrollBar1.get_Maximum() 
        + this.hScrollBar1.get_LargeChange());

    // If the offset does not make the Maximum less than zero, 
    // set its value.    
    if (this.pictureBox1.get_Image().get_Size().get_Height() 
        - pictureBox1.get_ClientSize().get_Height() > 0) {
            this.vScrollBar1.set_Maximum(
                this.pictureBox1.get_Image().get_Size().get_Height() 
                - pictureBox1.get_ClientSize().get_Height());
    }

    /* If the HScrollBar is visible, adjust the Maximum of the 
       VSCrollBar to account for the width of the HScrollBar.
     */
    if (this.hScrollBar1.get_Visible()) {
        this.vScrollBar1.set_Maximum(this.vScrollBar1.get_Maximum() 
            + this.hScrollBar1.get_Height());
    }

    this.vScrollBar1.set_LargeChange(this.vScrollBar1.get_Maximum() / 10);
    this.vScrollBar1.set_SmallChange(this.vScrollBar1.get_Maximum() / 20);

    // Adjust the Maximum value to make the raw Maximum value attainable 
    // by user interaction.
    this.vScrollBar1.set_Maximum(
        this.vScrollBar1.get_Maximum() 
        + this.vScrollBar1.get_LargeChange());
} //SetScrollBarValues

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Show: