I have a question related to trackbars in C#.
I
need to pass a string value to trackbar. Suppose I have a number 3. It
is saved as a string "three". Now I need to use this to set trackbar
value to 3. How do I do that in C#.
I tried
trackBarSpeed.Value.ToString() = hant; // hant = "three"
and trackBarSpeed.Value = int.Parse(hant); but nothing seems to work///// PLZ help....
Loading
AlanPosted Oct 17, 2008, 3:01 PM
The .NET framework doesn't have a method which converts a string representation of a number (i.e. "three") to the number itself (i.e. 3).
If you only wanted numbers from zero to ten, say, then you could do this:
private string[] numbers = new string[]{"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"};
// ...
int val = Array.IndexOf(numbers, hant);
if (val > - 1)
{
trackBarSpeed.Value = val;
}