Jump to content

Visual Studio – trackbar


xod
 Share

Recommended Posts

Is there a way to capture all the values of trackbar while sliding the scroll?
Scroll and ValueChanged event are working good in moderate speed.
However if I scroll the slider fast, some values are skipped.
I need in particular that the zero value in the middle of trackbar to be accurately detected.

Link to comment
Share on other sites

If it skips over zero, you can check for that. Use Math.Sign() to see if it changed from positive to negative, or vice-versa.

 

int oldValue = trackBar1.Value;

void trackBar1_Changed(object sender, EventArgs e)
{
    if (trackBar1.Value == 0 || Math.Sign(trackBar1.Value) != Math.Sign(oldValue))
    {
        myFunction();
    }
    
    oldValue = trackBar1.Value;
}

 

  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...