C# - 防止鼠标滚轮在面板中滚动

0 .net c# scroll panel mousewheel

我想防止在带有滚动条的面板中使用鼠标滚轮滚动,如何做到这一点?

我已经看到这个建议,但它不起作用:

panel.MouseWheel += new MouseEventHandler(MouseWheel);

void MouseWheel(object sender, MouseEventArgs e) {
  ((HandledMouseEventArgs)e).Handled = true;
}
Run Code Online (Sandbox Code Playgroud)

Lar*_*ech 5

尝试继承你自己的Panel并注释掉OnMouseWheel调用:

public class WheelessPanel : Panel {
  protected override void OnMouseWheel(MouseEventArgs e) {
    // base.OnMouseWheel(e);
  }
}
Run Code Online (Sandbox Code Playgroud)