代码
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 );
}
}
{
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 );
}
}
针对单个控件
代码
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;
}
}
{
numericUpDown1.MouseWheel += new MouseEventHandler(numericUpDown1_MouseWheel);
}
//取消滚轮事件
void numericUpDown1_MouseWheel(object sender, MouseEventArgs e)
{
HandledMouseEventArgs h = e as HandledMouseEventArgs;
if (h != null)
{
h.Handled = true;
}
}