Generated Image

如何禁止鼠标左键

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

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 则允许消息继续到达下一个筛选器或控件。  
 
 
 
 
 
posted @ 2007-02-12 21:09  桂圆  阅读(840)  评论(0编辑  收藏  举报