2011-08-09 20 views
0

有沒有辦法從文本框中取消WM_MOUSELEAVE消息?取消發送MouseLeave消息的文本框

我有另一個控件直接在它上面(我試圖獲得Windows繪製的邊框)。我正在手動調用該控件的MouseMove事件中的WM_MOUSEMOVE以使文本框周圍的Aero藍色邊框亮起。使用Spy ++,儘管我仍然處於邊界,但我看到它發射了WM_MOUSELEAVE。這會導致藍色邊框消失/重新出現在閃爍中。

編輯我試了@ Jeroen的回答,它減少了閃爍,但我仍然無法保持光亮或持續太久。

 if (m.Msg == (int)Win32Api.WindowsMessages.MouseLeave) 
     { 
      var mousePosition = PointToClient(MousePosition); 
      if (mousePosition.X < 0 || mousePosition.X > Width || 
       mousePosition.Y < 0 || mousePosition.Y > Height) 
       base.WndProc(ref m); 
      return; 
     } 

     base.WndProc(ref m); 
+0

您是否掛鉤了messageloop(WndProc)? – Jeroen

+0

如果您設置了控件的焦點,您能達到相同的效果嗎? – Mehran

+0

@Mehran - 我已經設定了重點。這是用戶將鼠標懸停在文本框上,但不會將其關注。 –

回答

1

也許這就是你要找的。這將需要你用tb取代TextBox的定義,但也許有一個更優雅的方式。

public class tb : TextBox 
      { 

       private const int WM_MOUSELEAVE = 0x02A3; 

       protected override void WndProc(ref Message m) 
       { 
        if (m.Msg == WM_MOUSELEAVE) 
        { 
         // not passing the message on, so does nothing. 
         // handle it yourself here or leave empty. 
        } 
        else 
        { 
         // otherwise let windows handle the message 
         base.WndProc(ref m); 
        } 
       } 
      } 
+0

我已更新我的問題。 –