能不能稍微具体一点,如果我先截获OnPaint消息怎么操作?

解决方案 »

  1.   

    需要实现System.Windows.Forms.IMessageFilter接口
    public class ListenOnPaint:System.Windows.Forms.IMessageFilter
    {

    public bool PreFilterMessage(ref Message m)
    {
    // TODO:  添加 ListenOnPaint.PreFilterMessage 实现
    if(m.Msg==0x000F)//WM_PAINT
    {
    Console.WriteLine("paint");
    return true;
    }
    return false;
    }
    }
    在main里
    [STAThread]
    static void Main() 
    {
    Application.AddMessageFilter(new ListenOnPaint());
    Application.Run(new Form1());
    }
    即可
      

  2.   

    你可以在需要截获OnPaint消息的类里面添加接口IMessageFilter比如在Form1中(下面只是示例,不确切,仅供参考):
    public class Form1 : Form ,IMessageFilter
    {
        void myPaint(...){
           //paint
        }
        public bool PreFilterMessage(ref Message m) {
           if (m.Msg == ON_PAINT ) {
              myPaint();
              return true;
           }
           return false;
        }
        static void Main()
        {
          Form1 frm = new Form1();
          Application.AddFilter(frm);
          Application.Run(frm);
        }
    }