In C # We can filter our application's messages so some's them don ' t get dispatched. The example below of the "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 to our needs
2. MainForm, which are 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 ());
}
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service