I have a Winforms app with a Toolstrip
and Datagridview
.
I'm attempting to implement MouseWheeling
on the ToolStripMenuItems
based on some information here:
I have added a Mousewheel
event to the DataGridView
as adding one to the base form didn't fire. My problem is that I can't find a way to detect when the mouse cursor is over an open ToolstripMenu
, it always says that it's over the DataGridView
.
I have tried several different approaches including the current code:
Public Shared Function FindControlAtPoint(container As Control, pos As Point) As Control
Dim child As Control
For Each c As Control In container.Controls
If c.Visible AndAlso c.Bounds.Contains(pos) Then
child = FindControlAtPoint(c, New Point(pos.X - c.Left, pos.Y - c.Top))
If child Is Nothing Then
Return c
Else
Return child
End If
End If
Next
Return Nothing
End Function
Public Shared Function FindControlAtCursor(form As Form) As Control
Dim pos As Point = Cursor.Position
If form.Bounds.Contains(pos) Then
Return FindControlAtPoint(form, form.PointToClient(Cursor.Position))
End If
Return Nothing
End Function