Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I have a trackbar wich moves between 1 and 10,
I want the programm to recognize if the trackbar is being moved from left to right or the other way around.
Like this:

if(trackbarfromlefttoright)
{
reakt different
}
else if(trackbarfromrighttoleft)
{
reakt different
}

how can I do that?
thanks in advance.
Posted

1 solution

Hi,

you could do it this way:
C#
int nTrackBarPosition = 0;
public Form1()
{
  InitializeComponent();
  nTrackBarPosition = trackBar1.Value;
}

private void trackBar1_Scroll(object sender, EventArgs e)
{
  if (nTrackBarPosition < trackBar1.Value)
    Console.WriteLine("MoveRight");
  else
    Console.WriteLine("MoveLeft");
  nTrackBarPosition = trackBar1.Value;
}
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 18-Feb-11 2:40am    
Easy enough? Correct, my 5.
--SA
Red&Black 18-Feb-11 2:53am    
I stilll cant get it to work..

if (nTrackBarPosition > trackBar1.Value)
{

for (int i = 0; i < 11; i++)
{
Px[i] = Px[i] - px;
}
}
else if(nTrackBarPosition < trackBar1.Value)
{

for (int i = 0; i < 11; i++)
{
Px[i] = Px[i] + px;
}
}


It still only does 1 thing no matter in wich way i move the trackbar...
JF2015 18-Feb-11 3:00am    
Have you tried setting breakpoints inside the if blocks to see if they are getting called? Please also don't forget to use the line: "nTrackBarPosition = trackBar1.Value;"
Red&Black 18-Feb-11 3:02am    
okay it was my mistake, I got it working now thank you very much (:
my 5 too.
JF2015 18-Feb-11 3:09am    
Do you mind to accept my answer so that it appears as solved in the forum? There should be a link called "Accept Answer". Thanks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900