c# Disable ScrollWheel on Trackbar

别等时光非礼了梦想. 提交于 2020-02-24 14:04:48

问题


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..


回答1:


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;


来源:https://stackoverflow.com/questions/34928924/c-sharp-disable-scrollwheel-on-trackbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!