要在C#中禁用或启用鼠标滚轮事件,您可以使用Windows Forms或WPF应用程序
Windows Forms:
DisableMouseWheel
的布尔变量。public partial class MainForm : Form
{
private bool DisableMouseWheel = false;
// ...
}
OnMouseWheel
方法以处理鼠标滚轮事件。protected override void OnMouseWheel(MouseEventArgs e)
{
if (!DisableMouseWheel)
base.OnMouseWheel(e);
}
DisableMouseWheel
变量来启用或禁用鼠标滚轮事件。private void ToggleMouseWheel()
{
DisableMouseWheel = !DisableMouseWheel;
}
WPF:
DisableMouseWheel
的布尔变量。public partial class MainWindow : Window
{
private bool DisableMouseWheel = false;
// ...
}
OnPreviewMouseWheel
方法以处理鼠标滚轮事件。protected override void OnPreviewMouseWheel(MouseWheelEventArgs e)
{
if (!DisableMouseWheel)
base.OnPreviewMouseWheel(e);
else
e.Handled = true;
}
DisableMouseWheel
变量来启用或禁用鼠标滚轮事件。private void ToggleMouseWheel()
{
DisableMouseWheel = !DisableMouseWheel;
}
现在,您可以根据需要调用ToggleMouseWheel()
方法来启用或禁用鼠标滚轮事件。