TrackBar.Minimum Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets the lower limit of the range this TrackBar is working with.
public:
property int Minimum { int get(); void set(int value); };
public int Minimum { get; set; }
member this.Minimum : int with get, set
Public Property Minimum As Integer
Property Value
The minimum value for the TrackBar. The default is 0.
Examples
The following code example demonstrates how to use the TickFrequency, 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 named 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.
internal:
System::Windows::Forms::TrackBar^ TrackBar1;
// Initialize 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.
internal System.Windows.Forms.TrackBar TrackBar1;
// Initialize 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.
Friend WithEvents TrackBar1 As System.Windows.Forms.TrackBar
' Initialize 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
Remarks
You can use the SetRange method to set both the Maximum and Minimum properties at the same time.