Mouse Move on the Panel Control
I want to catch the mouse move on a panel. I use the following Sub
Private
Sub Panel1_MouseMove(ByVal senderAsObject,ByVal eAs System.Windows.Forms.MouseEventArgs)Handles Panel1.MouseMoveEndSubBut when the mouse is on another control of the panel ( lets say a label ) , the program doesn't trigger the sub. I have to write another mosemove sub for the child control or I have to add handles behind the other sub . But I don't want to do it for each control.
Is there a way to solve this issue?
Below is a code snippet that shows how you can direct all mousemove events with a single mousemove handler. It's real primitive in that you will have to add logic to translate coordinates of child controls to the disired parent coordinates. This little demo will display the x,y pos of mouse relative to the control the mouse is moving over.
Public
Class Form1Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LoadMe.AddHandlers(Me)End SubPrivate Sub AddHandlers(ByVal CtrlIn As Control)For Each Item As Control In CtrlIn.ControlsAddHandler Item.MouseMove, AddressOf MyMouseMoveIf Item.Controls.Count > 0 ThenAddHandlers(Item)
End IfNextEnd SubPrivate Sub MyMouseMove(ByVal Sender As Object, ByVal e As MouseEventArgs)'you will have to write code to translate X-Y coordinates relative to the 'parent container's coordinates if neededMe.Text = e.X & "::" & e.YEnd SubEnd
Class
Ibrahim Malluf