问题
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