C#禁用鼠标滚轮
下面的代码直接禁用所有的鼠标滚轮响应
public partial class Form1 : Form, IMessageFilter { public Form1() { InitializeComponent(); } public bool PreFilterMessage(ref Message m) { if (m.Msg == 522) { return true; } else { return false; } } private void Form1_Load(object sender, EventArgs e) { Application.AddMessageFilter(this); } }
其中m.Msg还可以是下面这些消息
鼠标移动:512
鼠标左键:{down:513;up:514;double click:515 }
鼠标右键:{down:516;up:517}
鼠标滚轮:522
禁用其中指定控件可以这样
private void Form1_Load(object sender, EventArgs e) { comboBox1.MouseWheel += new MouseEventHandler(DisableMouseWheel); } //禁用滚轮事件 void DisableMouseWheel(object sender, MouseEventArgs e) { HandledMouseEventArgs h = e as HandledMouseEventArgs; if (h != null) { h.Handled = true; } }
扫描二维码推送至手机访问