How can I disable the valuechange with mouse wheel on trackbars? When scrolling down on the interface users can change trackbar values by mistake I'm using Windows forms c#. I couldn't find no property to stop this event..
Asked
Active
Viewed 2,133 times
1 Answers
2
I solved the issue with this: With normal event declaration..
Control = new TrackBar();
Control.MouseWheel += Control_MouseWheel;
private void Control_MouseWheel(object sender, MouseEventArgs e)
{
((HandledMouseEventArgs)e).Handled = true;
}
Using anonymous method
var Control = new TrackBar();
Control.MouseWheel += new MouseEventHandler(delegate(object sender, MouseEventArgs e)
{
((HandledMouseEventArgs)e).Handled = true;
});
What it does is to prevent further execution..
Edit: Using Labda expression as said by Sriram Sakthivel
Control.MouseWheel += (sender, e) =>((HandledMouseEventArgs)e).Handled = true;

miguelmpn
- 1,859
- 1
- 19
- 25
-
2What you have isn't a lambda expression. It is an anonymous method. With lambda it becomes much shorter. `Control.MouseWheel += (sender, e) =>((HandledMouseEventArgs)e).Handled = true;` – Sriram Sakthivel Jan 21 '16 at 16:32