方法一:禁用鼠标事件
public partial class Form1 : Form,IMessageFilter { public Form1() { InitializeComponent(); } #region IMessageFilter 成员 public bool PreFilterMessage(ref Message m) { if (m.Msg == 522) { return true; } else { return false; } } #endregion private void Form1_Load(object sender, EventArgs e) { Application.AddMessageFilter(this ); } }
鼠标移动:512
鼠标左键:
down:513
up: 514
double click:515
鼠标右键:
down:516
up:517
鼠标滚轮:522
方法二:针对单个控件,当前方法只屏蔽滚动事件
private void Form1_Load(object sender, EventArgs e) { numericUpDown1.MouseWheel += new MouseEventHandler(numericUpDown1_MouseWheel); } //取消滚轮事件 void numericUpDown1_MouseWheel(object sender, MouseEventArgs e) { HandledMouseEventArgs h = e as HandledMouseEventArgs; if (h != null) { h.Handled = true; } }
时间: 2024-12-14 18:09:45