C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
And: We add an event handler to execute code (written in C#) whenever the TrackBar is used.
Further: You can add event handlers by clicking on the lightning bolt. Many event handlers are available.
Note: Check the layout of the TrackBar in the following screenshot. It is laid out vertically.
SmallChange: This meanwhile determines how far the slider moves when the user presses up or down on the keyboard.
Note: The TrackBar will simply resize its scale to suit the Minimum and Maximum you choose.
And: If you increase the TickFrequency past the value of one, you can reduce the number of tick lines that are drawn.
Tip: In the body of the method trackBar1_Scroll, you can mutate other properties in your program based on the Value property of the TrackBar.
Here: In this program, we change the window title bar whenever the TrackBar is scrolled.
C# program that uses Scroll event handler
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void trackBar1_Scroll(object sender, EventArgs e)
{
// Set the window title text each time a scroll occurs.
this.Text = "Value: " + trackBar1.Value;
}
}
}