Can someone please help me in this, I need to use a trackbar (consider: trackBar1) to change the text of a label (consider: label1) according to the location of the trackbar. For example,
first trackbar location --> label text = Stock
second trackbar location --> label text = Shares
.
.
.
I appreciate your assitence.
Help in using the TrackBar
5 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Harto23 reputationPosted Sep 17, 2008, 12:56 AM EDT
if (trackbar1.Value == 0)
{
label1.Text = "shares";
}
.
.
.
Its easier and less time consuming
AlanRank #669 · 3.6K reputationPosted Sep 7, 2008, 12:28 PM EDT
Something like this perhaps:
if (trackBar1.Value <= (trackBar1.Minimum + trackBar1.Maximum)/2)
{
label1.Text = "Stock";
}
else
{
label1.Text = "Shares";
}
Harto23 reputationPosted Sep 7, 2008, 2:11 PM EDT
AlanRank #669 · 3.6K reputationPosted Sep 7, 2008, 3:23 PM EDT
It's just a matter of splitting the TrackBar's range up amongst how many cases you've got. For example, with 4 cases:
int range = trackBar1.Maximum - trackBar2.Minimum;
int distance = trackBar1.Value - trackBar1.Minimum;
if (trackBar1.Value <= range/4)
{
{
label1.Text = "Stock";
}
else if (distance > range/4 && distance <= range/2)
{
label1.Text = "Shares";
}
else if (distance > range/2 && distance <= range * 3/4)
{
label1.Text = "Cash";
}
else
{
label1.Text = "Property";
}
Harto23 reputationPosted Sep 7, 2008, 4:02 PM EDT