c# - prevent mousewheel scrolling in panel

*爱你&永不变心* 提交于 2021-01-25 07:10:02

问题


I want to prevent scrolling with the mousewheel in a panel with a scrollbar, how can ido this?

I have seen this suggested, but it's not working:

panel.MouseWheel += new MouseEventHandler(MouseWheel);

void MouseWheel(object sender, MouseEventArgs e) {
  ((HandledMouseEventArgs)e).Handled = true;
}

回答1:


Try inheriting your own Panel and just comment out the OnMouseWheel call:

public class WheelessPanel : Panel {
  protected override void OnMouseWheel(MouseEventArgs e) {
    // base.OnMouseWheel(e);
  }
}



回答2:


If you provide a user with a scrollable control, why would you then prevent them from scrolling it? If you don't want them to scroll, don't give them scroll bars.

If I came across a UI like that I would dislike it and only use it if I absolutely had to.



来源:https://stackoverflow.com/questions/21261285/c-sharp-prevent-mousewheel-scrolling-in-panel

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