Occurs when the
Value property of a track bar changes, either by movement of the scroll box or by manipulation in code.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)
Visual Basic (Declaration)
Public Event ValueChanged As EventHandler
Dim instance As TrackBar
Dim handler As EventHandler
AddHandler instance.ValueChanged, handler
public event EventHandler ValueChanged
public:
event EventHandler^ ValueChanged {
void add (EventHandler^ value);
void remove (EventHandler^ value);
}
/** @event */
public void add_ValueChanged (EventHandler value)
/** @event */
public void remove_ValueChanged (EventHandler value)
JScript supports the use of events, but not the declaration of new ones.
You can use this event to update other controls when the value represented in the track bar changes.
For more information about handling events, see Consuming Events.
The following code example demonstrates how to use the TickStyle, Minimum, and Maximum members and how to handle the ValueChanged event. To run the example, paste the following code into a form that contains a TrackBar control name TrackBar1 and a TextBox control named TextBox1. Call the InitializeTrackBar method from the form's constructor or Load event-handling method.
'Declare a new TrackBar object.
Friend WithEvents TrackBar1 As System.Windows.Forms.TrackBar
' Initalize the TrackBar and add it to the form.
Private Sub InitializeTrackBar()
Me.TrackBar1 = New System.Windows.Forms.TrackBar
' Set the TickStyle property so there are ticks on both sides
' of the TrackBar.
TrackBar1.TickStyle = TickStyle.Both
' Set the minimum and maximum number of ticks.
TrackBar1.Minimum = 10
TrackBar1.Maximum = 100
' Set the tick frequency to one tick every ten units.
TrackBar1.TickFrequency = 10
TrackBar1.Location = New System.Drawing.Point(75, 30)
Me.Controls.Add(Me.TrackBar1)
End Sub
' Handle the TrackBar.ValueChanged event by calculating a value for
' TextBox1 based on the TrackBar value.
Private Sub TrackBar1_ValueChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles TrackBar1.ValueChanged
TextBox1.Text = System.Math.Round(TrackBar1.Value / 10)
End Sub
//Declare a new TrackBar object.
internal System.Windows.Forms.TrackBar TrackBar1;
// Initalize the TrackBar and add it to the form.
private void InitializeTrackBar()
{
this.TrackBar1 = new System.Windows.Forms.TrackBar();
TrackBar1.Location = new System.Drawing.Point(75, 30);
// Set the TickStyle property so there are ticks on both sides
// of the TrackBar.
TrackBar1.TickStyle = TickStyle.Both;
// Set the minimum and maximum number of ticks.
TrackBar1.Minimum = 10;
TrackBar1.Maximum = 100;
// Set the tick frequency to one tick every ten units.
TrackBar1.TickFrequency = 10;
// Associate the event-handling method with the
// ValueChanged event.
TrackBar1.ValueChanged +=
new System.EventHandler(TrackBar1_ValueChanged);
this.Controls.Add(this.TrackBar1);
}
// Handle the TrackBar.ValueChanged event by calculating a value for
// TextBox1 based on the TrackBar value.
private void TrackBar1_ValueChanged(object sender, System.EventArgs e)
{
TextBox1.Text = (System.Math.Round(TrackBar1.Value/10.0)).ToString();
}
//Declare a new TrackBar object.
internal:
System::Windows::Forms::TrackBar^ TrackBar1;
// Initalize the TrackBar and add it to the form.
private:
void InitializeTrackBar()
{
this->TrackBar1 = gcnew System::Windows::Forms::TrackBar;
TrackBar1->Location = System::Drawing::Point( 75, 30 );
// Set the TickStyle property so there are ticks on both sides
// of the TrackBar.
TrackBar1->TickStyle = TickStyle::Both;
// Set the minimum and maximum number of ticks.
TrackBar1->Minimum = 10;
TrackBar1->Maximum = 100;
// Set the tick frequency to one tick every ten units.
TrackBar1->TickFrequency = 10;
// Associate the event-handling method with the
// ValueChanged event.
TrackBar1->ValueChanged += gcnew System::EventHandler( this, &Form1::TrackBar1_ValueChanged );
this->Controls->Add( this->TrackBar1 );
}
// Handle the TrackBar.ValueChanged event by calculating a value for
// TextBox1 based on the TrackBar value.
void TrackBar1_ValueChanged( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
TextBox1->Text = (System::Math::Round( TrackBar1->Value / 10.0 )).ToString();
}
//Declare a new TrackBar object.
System.Windows.Forms.TrackBar trackBar1;
// Initalize the TrackBar and add it to the form.
private void InitializeTrackBar()
{
this.trackBar1 = new System.Windows.Forms.TrackBar();
trackBar1.set_Location(new System.Drawing.Point(75, 30));
// Set the TickStyle property so there are ticks on both sides
// of the TrackBar.
trackBar1.set_TickStyle(TickStyle.Both);
// Set the minimum and maximum number of ticks.
trackBar1.set_Minimum(10);
trackBar1.set_Maximum(100);
// Set the tick frequency to one tick every ten units.
trackBar1.set_TickFrequency(10);
// Associate the event-handling method with the
// ValueChanged event.
trackBar1.add_ValueChanged(new System.EventHandler(
trackBar1_ValueChanged));
this.get_Controls().Add(this.trackBar1);
} //InitializeTrackBar
// Handle the TrackBar.ValueChanged event by calculating a value for
// textBox1 based on the TrackBar value.
private void trackBar1_ValueChanged(Object sender, System.EventArgs e)
{
textBox1.set_Text(((System.Double)System.Math.Round(
trackBar1.get_Value() / 10.0)).ToString());
} //trackBar1_ValueChanged
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, 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