Form message filter : Form : GUI Windows Forms C# Examples


C# Examples » GUI Windows Forms » Form »

 

Form message filter









    
using  System;
using  System.Windows.Forms;

public  class  mainForm  :  System.Windows.Forms.Form
{
    private  MyMessageFilter  msgFliter  =  new  MyMessageFilter();

    public  mainForm()
    {
        Application.ApplicationExit  +=  new  EventHandler(Form_OnExit);

        Application.AddMessageFilter(msgFliter);        
    }

    [STAThread]
    static  void  Main()  
    {
        Application.Run(new  mainForm());
    }
    private  void  Form_OnExit(object  sender,  EventArgs  evArgs)  
    {
        Application.RemoveMessageFilter(msgFliter);
    }
}

public  class  MyMessageFilter  :  IMessageFilter  
{
    public  bool  PreFilterMessage(ref  Message  m)  
    {
        //  Intercept  the  left  mouse  button  down  message.
        if  (m.Msg  ==  513)  
        {
            Console.WriteLine("WM_LBUTTONDOWN  is:  "  +  m.Msg);
            return  true;
        }
        return  false;
    }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo GUI Windows Forms
» Form