Linux中国 Linux中国门户站!
设为主页 设为主页
收藏本站 收藏本站
 
当前位置 :首页 ->编程语言 ->ASP.NET ->正文

在C#中实现消息过滤

来源:Linuxdby.com 作者:Webmaster 时间:2007-04-28 点击: [收藏] [投稿]
In C# we can filter our application's messages so some of them don't get dispatched. See the example below of how to prevent the user from clicking the Left Mouse button in our application:

// created on 20.10.2001 at 18:04
//This example has 2 classes
//1. MyFilter, which exposes the IMesageFilter interface
//The PreFilterMessage method is overriden for our needs
//2. MainForm, which is our main form
using System;
using System.Windows.Forms;
class MyFilter:IMessageFilter //gets the left mouse button messages
{
public bool PreFilterMessage(ref Message m)
{
  if (m.Msg>=513 && m.Msg<=515)
   {
    Console.WriteLine("mouse left button event NOT accepted!Filter working...");
    return(true);
   }
  return(false);
}
}
class MainForm : Form
{
private Button btn=new Button();
public MainForm() //MainForm's constructor
{
  //let's put a button on the form
  btn.Left=30;
  btn.Top=30;
  btn.Width=150;
  btn.Text="Try to Click me!";
  btn.Visible=true;
  this.Controls.Add(btn);
}
public static void Main()
{
  
  //let's put some filter on our Application's message queue
  Application.AddMessageFilter(new MyFilter());
  //create the MainForm object and make it visible
  Application.Run(new MainForm());
}
}






 如果您对本文有任何疑问或者建议,请到讨论区发表您的意见: >> 论坛入口 <<



上一篇:在ASP.NET中的变量数值管理--看了这个我基本上对原来的REQUEST.FORM的方法传递变量绝   下一篇:ASP.NET Caching(2)

文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【我要投稿】 【论坛讨论
更多相关文章
Power by linux-cn.com 粤ICP备05006655号