Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Gets the corresponding control (if any) that is over the specified mouse point.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <example> This is a code example.
- ''' <code>
- ''' Dim ctrl As Control = GetControlFromPoint(Me, Cursor.Position)
- ''' If (ctrl IsNot Nothing) Then
- ''' Console.WriteLine(ctrl.Name)
- ''' End If
- ''' </code>
- ''' </example>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="container">
- ''' The source container of controls where to search for.
- ''' <para></para>
- ''' Normally a <see cref="Form"/>, but you can specify another <see cref="Control"/> that contains a <see cref="ControlCollection"/>.
- ''' </param>
- '''
- ''' <param name="pt">
- ''' The mouse point.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' The resulting <see cref="Control"/>, or <see langword="Nothing"/>.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- 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
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Gets the corresponding control (if any) that is over the specified mouse point.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <example> This is a code example.
- ''' <code>
- ''' Dim ctrl As Control = GetControlFromPoint(Me)
- ''' If (ctrl IsNot Nothing) Then
- ''' Console.WriteLine(ctrl.Name)
- ''' End If
- ''' </code>
- ''' </example>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="container">
- ''' The source container of controls where to search for.
- ''' <para></para>
- ''' Normally a <see cref="Form"/>, but you can specify another <see cref="Control"/> that contains a <see cref="ControlCollection"/>.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' The resulting <see cref="Control"/>, or <see langword="Nothing"/>.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- Public Shared Function GetControlFromPoint(ByVal container As Control) As Control
- Return GuiUtil.GetControlFromPoint(container, Cursor.Position)
- End Function
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Gets the corresponding control (if any) that is over the specified point.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <example> This is a code example.
- ''' <code>
- ''' Dim ctrl As Control = GetControlFromPoint(Me, Cursor.Position)
- ''' If (ctrl IsNot Nothing) Then
- ''' Console.WriteLine(ctrl.Name)
- ''' End If
- ''' </code>
- ''' </example>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="form">
- ''' The source <see cref="Form"/> where to search for.
- ''' </param>
- '''
- ''' <param name="pt">
- ''' The mouse point, in non-relative screen coordinates.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' The resulting <see cref="Control"/>, or <see langword="Nothing"/>.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- Public Shared Function GetControlFromPoint(ByVal form As Form, ByVal pt As Point) As Control
- Return GuiUtil.GetControlFromPoint(DirectCast(form, Control), pt)
- End Function
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Gets the corresponding control (if any) that is over the current mouse point.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <example> This is a code example.
- ''' <code>
- ''' Dim ctrl As Control = GetControlFromPoint(Me)
- ''' If (ctrl IsNot Nothing) Then
- ''' Console.WriteLine(ctrl.Name)
- ''' End If
- ''' </code>
- ''' </example>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="form">
- ''' The source <see cref="Form"/> where to search for.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' The resulting <see cref="Control"/>, or <see langword="Nothing"/>.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- Public Shared Function GetControlFromPoint(ByVal form As Form) As Control
- Return GuiUtil.GetControlFromPoint(DirectCast(form, Control), Cursor.Position)
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement