From looking at aygunes.myopenid.com answer, I made this version on Vb.Net that recursively add MouseLeaveHandlers to all the controls in the form, and then use nice Clientrectangle.Contains (pt) to check if the mousecursor is enabled or not. I work like a charm. Cred goes to aygunes.myopenid.com.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load AddMouseLeaveHandlers() End Sub Sub AddMouseLeaveHandlers() For Each c As Control In Me.Controls HookItUp(c) Next AddHandler Me.MouseLeave, AddressOf CheckMouseLeave End Sub Sub HookItUp(ByVal c As Control) AddHandler c.MouseLeave, AddressOf CheckMouseLeave If c.HasChildren Then For Each f As Control In c.Controls HookItUp(f) Next End If End Sub Private Sub CheckMouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Dim pt As Point = PointToClient(Cursor.Position) If ClientRectangle.Contains(pt) = False Then MsgBox("Mouse left form") End If End Sub
source share