如何禁止鼠标左键

首先我们要将窗口类继承于

System.Windows.Forms.Form, IMessageFilter

namespace WindowsApplication1
{
    public partial class Form1 : System.Windows.Forms.Form, IMessageFilter
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            Application.AddMessageFilter(this);
            MessageBox.Show("鼠标左键已被禁止,请用Tab键执行操作!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
 
 
 
        public bool PreFilterMessage(ref System.Windows.Forms.Message SystemMessage)
        {
            if (SystemMessage.Msg >= 513 && SystemMessage.Msg <= 515)
            {//不响应鼠标左键消息                
                return true;
            }
            return false;
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            Application.RemoveMessageFilter(this);
            MessageBox.Show("鼠标左键已解禁,可以执行操作!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
    
        }
 
 
    }
}
 
IMessageFilter 是个接口 
 
public abstract new System.Boolean PreFilterMessage ( System.Windows.Forms.Message m )
    System.Windows.Forms.IMessageFilter 的成员
 
摘要:
 在调度消息之前将其筛选出来。  
 
参数:
m: 要调度的消息。无法修改此消息。 
 
返回值:
 true 筛选消息并防止消息被调度;false 则允许消息继续到达下一个筛选器或控件。  
 
 
 
 
 

转载于:https://www.cnblogs.com/zbqy/archive/2007/02/12/648726.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值