Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi
can i run a code with "mouse move" in all forms or controls.

in form i have 3 tabpage , datagridviews ,buttons and labels

What I have tried:

Private Sub rapor_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles rapor.MouseMove



   End Sub
Posted
Updated 15-May-20 0:46am
v2
Comments
Member 14588284 15-May-20 6:48am    
i found codes like this
in form load:
For Each cntrl As Control In Me.Controls
AddHandler cntrl.MouseMove, AddressOf Control_MouseMove
Next

Private Sub Control_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Dim cntrl As Control = CType(sender, Control)
MsgBox("hell")
End Sub

but tihs code run only mouse on tabpage

1 solution

I assume from your question, that you want to run code in your specific app whenever the mouse moves regardless of where on the screen the mouse pointer is, and regardless of what pp has the focus. If so, then you might want to rethink this.

It's possible, but ... it requires adding a Global Hook into the whole system, and that's very dangerous - if your code doesn't work perfectly every time then your whole system will become unstable, and may require a reload from a recent backup to get it working again at all - developing global hooks code is not a job for a beginner, not even slightly and should be thought about and pre-planned (including those essential backups) carefully before you start coding.

If you decide to ignore this and proceed, then start here: https://support.microsoft.com/en-gb/help/319524/how-to-set-a-hook-in-visual-basic-net[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900