Question

This is probably a n00b query. I have a need where I want to change the trackbar value based on a mouse down event. This I achieved as follows:

private void MoveTrackBarToMouseClickLocation(TrackBar a_tBar, int a_mouseX)
{
    // Jump to the clicked location

        double dblValue;
        dblValue = ((double)a_mouseX / (double)a_tBar.Width) * (a_tBar.Maximum -    a_tBar.Minimum);
        a_tBar.Value = Convert.ToInt32(dblValue);
}

That part works fine. I am having trouble getting the scroll working while the mouse button is pressed. e.g. If I click on the trackbar and it takes me to say value 50 with the mouse down, I want to be able to scroll right or left (from value=50) while that mouse is down.

I hope I have made my small issue clear. Any help is appreciated. Thanks

Was it helpful?

Solution

You need to execute your code in the MouseMove event, as well as the MouseDown event.

This event occurs when the mouse is moved while one of the buttons is held down. In contrast, the MouseDown event that you currently handle only gets raised once each time the mouse button is pressed down. That's why the TrackBar is not moving when the user moves the mouse, but is working properly the first time the button is pressed.

You didn't show the code where you wired up the event handlers and/or call the MoveTrackBarToMouseClickLocation function, so that's as specific as I can get. But if you managed to wire up the MouseDown event already, this should be a simple fix.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top