spreadsheetgear插件屏蔽鼠标右键的方法


刚开始用的Mouse_up,虽然能捕获事件,但是没有KeyPress事件的Handled属性。

发现一个相对简单的方法。

1.先让窗体类继承IMessageFilter接口
2.在构造函数中添加:Application.AddMessageFilter(this);
3.在代码中加入:

复制代码 代码如下:

public bool PreFilterMessage(ref System.Windows.Forms.Message MyMessage)
{
    //不响应鼠标右键消息
    if(MyMessage.Msg>=516 && MyMessage.Msg<=517)
    {
        return true;
    }
    return false;
}

4. 你可以将Application.AddMessageFilter()放到任何你想起作用的地方,也随时可以Application.RemoveMessageFilter(this)

按步骤即可成功屏蔽。

屏蔽之后还有个问题,就是双击之后,系统自带的内容区的右键也被屏蔽了。


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3