C#禁用numericUpDown控件鼠标中键滚轮消息响应

C#禁用numericUpDown控件鼠标中键滚轮消息响应

 

numericUpDown_roadgain.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;
    }
}

可以使用Lambda写法简化:

numericUpDown_roadgain.MouseWheel += (s,e)=>
{
    HandledMouseEventArgs h = e as HandledMouseEventArgs;
    if (h != null)
    {
        h.Handled = true;
    }
};

 

posted @ 2021-03-11 11:20  passtime  阅读(542)  评论(0编辑  收藏  举报