编程资料集中营
 | 网站首页 | 文章中心 | 编程资料2 | 软件下载 | BT下载 | 八卦星闻 | 音乐在线 | 在线游戏 | 免费电影 | 给我留言 | 
        
【字体:
进入问吧

本站地址:http://www.bajiao123.com

作者:佚名    文章来源:不详    点击数:    更新时间:2007-4-2    

有難度的問題: 不改變Control的Enable,如何避免Control產生點擊事件?


請注意: 避免Control產生點擊事件不是指我們添加的點擊事件不執行﹐而是根本不讓Control得到鼠標點擊的消息,從而避免它發生任何變化.
類似C 中接獲和消毀消息.
請高手們相助~~~
jimh(jimmy) 于 2005-6-13 16:34:32
在form_load事件加上Application.AddMessageFilter(IMessageFilter)就可以了,
参数是一个实现了IMessageFilter的类的实例。
public class ControlMouseDown: IMessageFilter
{
public intptr ControlHandler;
public bool PreFilterMessage(ref Message m) //实现接口方法
{
if (m.Msg == WM_MouseDown && m.HWnd) return true; //过滤
return false;
}
}
fengfangfang 于 2005-6-13 16:34:47
在鼠标或key的事件中,移去焦点
jimh(jimmy) 于 2005-6-13 16:35:46
在form_load事件加上Application.AddMessageFilter(IMessageFilter)就可以了,
参数是一个实现了IMessageFilter的类的实例。
public class ControlMouseDown: IMessageFilter
{
public intptr ControlHandler;
public bool PreFilterMessage(ref Message m) //实现接口方法
{
if (m.Msg == WM_MouseDown && m.HWnd == ControlHandler) return true; //过滤
return false;
}
}
stonegoldaustin(特醇中南海) 于 2005-6-13 16:46:52
以BUTTON为例,先建立一个集成BUTTON的类
using System;
using System.Windows.Forms;
namespace WndProc
{
public class ClsButton : System.Windows.Forms.Button
{
private const int WM_LBUTTONDOWN = 0x201;
public ClsButton()
{
}

protected override void WndProc(ref Message m)
{
switch(m.Msg)
{
case WM_LBUTTONDOWN:
MessageBox.Show("Not Avalible");
break;
default:
base.WndProc(ref m);
break;
}
}
}
}

然后再FORM中加入该类,左键已经被屏蔽了(可通过添加CLICK事件察看)
private WndProc.ClsButton Command;
private void InitializeComponent()
{
this.Command = new WndProc.ClsButton();
this.SuspendLayout();
this.Command.Location = new System.Drawing.Point(0, 0);
this.Command.Name = "Command";
this.Command.Size = new System.Drawing.Size(100, 100);
this.Command.TabIndex = 0;
this.Command.Click = new System.EventHandler(this.Command_Click);
this.Controls.Add(this.Command);
}
private void Command_Click(object sender, System.EventArgs e)
{
MessageBox.Show("Click");
}
sqfeiyu(流星雨) 于 2005-6-13 16:52:54
沒話可說, 服了!!!
明天早上結貼.
mathsword(梦在流浪) 于 2005-6-13 17:36:48
mark
xamaizi(ecogiser) 于 2005-07-01 17:38:00this.button1.Click = new System.EventHandler(this.button1_Click);    

进入问吧

本站地址:http://www.bajiao123.com

文章录入:admin    责任编辑:admin 
  • 上一篇文章:

  • 下一篇文章: 没有了
  • 高级搜索
    编程资料集中营