Export (0) Print
Expand All

TrackBar.SmallChange Property

Gets or sets the value 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 Value

Type: System.Int32
A numeric value. The default value is 1.

ExceptionCondition
ArgumentException

The assigned value is less than 0.

When the user presses one of the arrow keys, the Value property changes according to the value set in the SmallChange property.

You might consider setting the value of SmallChange to a percentage of the value of the Height (for a vertically oriented track bar) or Width (for a horizontally oriented track bar) property. This sets the distance your track bar moves proportionate to its size.

The following code example displays a form that contains a TrackBar control and a TextBox control. The example demonstrates setting the Maximum, TickFrequency, LargeChange, and SmallChange properties and handling the Scroll event. The TextBox contents are updated to the Value property value when the Scroll event occurs.

using System;
using System.Drawing;
using System.Windows.Forms;

public class Form1 : System.Windows.Forms.Form
{
    private System.Windows.Forms.TrackBar trackBar1;
    private System.Windows.Forms.TextBox textBox1;

    [STAThread]
    static void Main() 
    {
        Application.Run(new Form1());
    }

    public Form1()
    {
        this.textBox1 = new System.Windows.Forms.TextBox();
        this.trackBar1 = new System.Windows.Forms.TrackBar();

        // TextBox for TrackBar.Value update. 
        this.textBox1.Location = new System.Drawing.Point(240, 16);
        this.textBox1.Size = new System.Drawing.Size(48, 20);

        // Set up how the form should be displayed and add the controls to the form. 
        this.ClientSize = new System.Drawing.Size(296, 62);
        this.Controls.AddRange(new System.Windows.Forms.Control[] {this.textBox1,this.trackBar1});
        this.Text = "TrackBar Example";

        // Set up the TrackBar. 
        this.trackBar1.Location = new System.Drawing.Point(8, 8);
        this.trackBar1.Size = new System.Drawing.Size(224, 45);
        this.trackBar1.Scroll += new System.EventHandler(this.trackBar1_Scroll);

        // The Maximum property sets the value of the track bar when 
        // the slider is all the way to the right.
        trackBar1.Maximum = 30;

        // The TickFrequency property establishes how many positions 
        // are between each tick-mark.
        trackBar1.TickFrequency = 5;

        // The LargeChange property sets how many positions to move 
        // if the bar is clicked on either side of the slider.
        trackBar1.LargeChange = 3;

        // The SmallChange property sets how many positions to move 
        // if the keyboard arrows are used to move the slider.
        trackBar1.SmallChange = 2;
    }


    private void trackBar1_Scroll(object sender, System.EventArgs e)
    {
        // Display the trackbar value in the text box.
        textBox1.Text = "" + trackBar1.Value;
    }
}

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft