For the original article, see:Two Methods for intercepting messages on form in winform
The defwndproc Method for reload form is commonly used, for example, intercepting the message pressed by the mouse:
Protected override void defwndproc (ref message m)
{
If (M. MSG = 0x0201)
{
MessageBox. Show (M. msg. tostring ());
}
Else
{
Base. defwndproc (ref m );
}
}
You can also use the imessagefilter interface: public class messagefilter: imessagefilter
{
Public bool prefiltermessage (ref message m)
{
If (M. MSG = 0x0201)
{
MessageBox. Show ("wm_lbuttondown is:" + M. msg );
Return true;
}
Return false;
}
}
Use the application. addmessagefilter method, for example:
Private Static messagefilter msgfliter = new messagefilter ();
Register the message filter in the main method:
Application. addmessagefilter (msgfliter );
To cancel registration, you can call the application. removemessagefilter method.
Here is a Windows messageid enumeration, which is very useful and has forgotten the address several times. Please save it here this time.
Windows Message ID Constants