2012-04-11 30 views
2

是否可以爲窗口的邊框創建MouseEnter-Event?我的意思是最小化和最大化按鈕。因爲如果我爲Form1設置事件,它只在我處於表格內時才起作用,但不在邊框和按鈕上。C#MouseEnter-整個窗口的事件

+0

這裏http://stackoverflow.com/questions/3312752/capturing-mouse-keyboard-events-outside-of-form-app在後臺運行可能會對你有所幫助。 – OammieR 2012-04-11 09:08:01

回答

3

您可以覆蓋的WndProc你形成並可以檢測到鼠標移動

protected override void WndProc(ref Message m) 
     { 
      base.WndProc(ref m); 
      // mouse in window or in Border and max, close & min buttons  
      if (m.Msg == 0xa0 || m.Msg == 0x200) 
      { 
       //Do some thing 
      } 
     } 
+0

注意:我的代碼檢測鼠標移動,所以如果你只需要鼠標輸入,你可以使一個全局變量(布爾)和它周圍玩耍,以避免多次調用 – 2012-04-11 09:23:22

+1

非常感謝你! – asdasdad 2012-04-11 09:36:56

+0

+1,不客氣 – 2012-04-11 09:55:47