''' ---------------------------------------------------------------------------------------------------- ''' ''' Gets the corresponding control (if any) that is over the specified mouse point. ''' ''' ---------------------------------------------------------------------------------------------------- ''' This is a code example. ''' ''' Dim ctrl As Control = GetControlFromPoint(Me, Cursor.Position) ''' If (ctrl IsNot Nothing) Then ''' Console.WriteLine(ctrl.Name) ''' End If ''' ''' ''' ---------------------------------------------------------------------------------------------------- ''' ''' The source container of controls where to search for. ''' ''' Normally a , but you can specify another that contains a . ''' ''' ''' ''' The mouse point. ''' ''' ---------------------------------------------------------------------------------------------------- ''' ''' The resulting , or . ''' ''' ---------------------------------------------------------------------------------------------------- Public Shared Function GetControlFromPoint(ByVal container As Control, ByVal pt As Point) As Control Dim child As Control = container Dim nextChild As Control = Nothing Do While True For Each ctrl As Control In child.Controls If (ctrl.Visible) AndAlso (ctrl.ClientRectangle.Contains(ctrl.PointToClient(pt))) Then nextChild = ctrl Exit For End If Next ctrl If (nextChild Is Nothing) Then If (container.ClientRectangle.Contains(container.PointToClient(pt))) Then Return container Else Return Nothing End If ElseIf (child.Equals(nextChild)) Then Exit Do Else child = nextChild End If Loop Return child End Function ''' ---------------------------------------------------------------------------------------------------- ''' ''' Gets the corresponding control (if any) that is over the specified mouse point. ''' ''' ---------------------------------------------------------------------------------------------------- ''' This is a code example. ''' ''' Dim ctrl As Control = GetControlFromPoint(Me) ''' If (ctrl IsNot Nothing) Then ''' Console.WriteLine(ctrl.Name) ''' End If ''' ''' ''' ---------------------------------------------------------------------------------------------------- ''' ''' The source container of controls where to search for. ''' ''' Normally a , but you can specify another that contains a . ''' ''' ---------------------------------------------------------------------------------------------------- ''' ''' The resulting , or . ''' ''' ---------------------------------------------------------------------------------------------------- Public Shared Function GetControlFromPoint(ByVal container As Control) As Control Return GuiUtil.GetControlFromPoint(container, Cursor.Position) End Function ''' ---------------------------------------------------------------------------------------------------- ''' ''' Gets the corresponding control (if any) that is over the specified point. ''' ''' ---------------------------------------------------------------------------------------------------- ''' This is a code example. ''' ''' Dim ctrl As Control = GetControlFromPoint(Me, Cursor.Position) ''' If (ctrl IsNot Nothing) Then ''' Console.WriteLine(ctrl.Name) ''' End If ''' ''' ''' ---------------------------------------------------------------------------------------------------- ''' ''' The source where to search for. ''' ''' ''' ''' The mouse point, in non-relative screen coordinates. ''' ''' ---------------------------------------------------------------------------------------------------- ''' ''' The resulting , or . ''' ''' ---------------------------------------------------------------------------------------------------- Public Shared Function GetControlFromPoint(ByVal form As Form, ByVal pt As Point) As Control Return GuiUtil.GetControlFromPoint(DirectCast(form, Control), pt) End Function ''' ---------------------------------------------------------------------------------------------------- ''' ''' Gets the corresponding control (if any) that is over the current mouse point. ''' ''' ---------------------------------------------------------------------------------------------------- ''' This is a code example. ''' ''' Dim ctrl As Control = GetControlFromPoint(Me) ''' If (ctrl IsNot Nothing) Then ''' Console.WriteLine(ctrl.Name) ''' End If ''' ''' ''' ---------------------------------------------------------------------------------------------------- ''' ''' The source where to search for. ''' ''' ---------------------------------------------------------------------------------------------------- ''' ''' The resulting , or . ''' ''' ---------------------------------------------------------------------------------------------------- Public Shared Function GetControlFromPoint(ByVal form As Form) As Control Return GuiUtil.GetControlFromPoint(DirectCast(form, Control), Cursor.Position) End Function