C# 禁用鼠标中间键

关于 C# System.Windows.Forms.NumericUpDown 控件,如何禁用鼠标中间键?

方法如下:

声明一个事件:

 Num_DiscountAmount.MouseWheel +=new MouseEventHandler(Num_DiscountAmount_MouseWheel);

编写一个事件

private void  Num_DiscountAmount_MouseWheel(object sender, MouseEventArgs e)
{
HandledMouseEventArgs h = e as HandledMouseEventArgs;
if (h != null)
{
h.Handled = true;
}
}

 

还有 第三方控件 DevExpress.XtraEditors.SpinEdit ,如何禁用鼠标中间键 ?

方法如下:

声明事件: (SpinEdit1.Controls[0] as DevExpress.XtraEditors.TextBoxMaskBox).MouseWheel += new MouseEventHandler(Frm_MouseWheel);

编写事件:

void Frm_MouseWheel(object sender, MouseEventArgs e)
{
if (e.Delta != 0)
DevExpress.Utils.DXMouseEventArgs.GetMouseArgs(e).Handled = true;
}

 

 

posted @ 2013-03-06 12:18  chenaran  阅读(676)  评论(0编辑  收藏  举报