yardboy27
yardboy27

Reputation: 1

Hot keying Ctrl + Scroll Wheel to increase/decrease the track value in C#

I am creating a Windows Form application that has a scroll bar which adjusts movement speed for a stage controller. I would like to give users the option to incrementally adjust the speed by pressing the Ctrl key and scrolling the mouse wheel without having their mouse hover over the track bar such that:

I am probably approaching this from the wrong angle, but this is my code thus far:

private void adjustTrackBarWithMouse(object sender, MouseEventArgs e, Keys keyData)
        {
            if ( (e.Delta > 0) & (keyData == Keys.Control) )
            {
                // user scrolled up with Ctrl, increase the track bar
                trackBarSpeed.Value = Math.Min(trackBarSpeed.Value + trackBarSpeed.SmallChange, trackBarSpeed.Maximum);
                trackBarSpeed_UpdateLabel();
            }
            else if ( (e.Delta < 0) & (keyData == Keys.Control) )
            {
                // user scrolled down with Ctrl, decrease the track bar
                trackBarSpeed.Value = Math.Max(trackBarSpeed.Value - trackBarSpeed.SmallChange, trackBarSpeed.Minimum);
                trackBarSpeed_UpdateLabel();
            }
        }

where trackBarSpeed_UpdateLabel() is simply a function that will update a label that displays the track bar's value.

When I run this code, nothing happens, and the tack bar only increases by large amounts when I hover over the track bar and use the scroll wheel (which is not what I want to happen).

Let me know what I should do! Can I edit the function above to accomplish my goal, or is there a "protected override" function similar to how you can rebind the hotkeys in C# that I can edit to accomplish my goal?

Upvotes: 0

Views: 364

Answers (0)

Related Questions