Advertisement
Guest User

Untitled

a guest
Jun 14th, 2016
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.53 KB | None | 0 0
  1.  
  2. ''' ----------------------------------------------------------------------------------------------------
  3. ''' <summary>
  4. ''' Gets the corresponding control (if any) that is over the specified mouse point.
  5. ''' </summary>
  6. ''' ----------------------------------------------------------------------------------------------------
  7. ''' <example> This is a code example.
  8. ''' <code>
  9. ''' Dim ctrl As Control = GetControlFromPoint(Me, Cursor.Position)
  10. ''' If (ctrl IsNot Nothing) Then
  11. ''' Console.WriteLine(ctrl.Name)
  12. ''' End If
  13. ''' </code>
  14. ''' </example>
  15. ''' ----------------------------------------------------------------------------------------------------
  16. ''' <param name="container">
  17. ''' The source container of controls where to search for.
  18. ''' <para></para>
  19. ''' Normally a <see cref="Form"/>, but you can specify another <see cref="Control"/> that contains a <see cref="ControlCollection"/>.
  20. ''' </param>
  21. '''
  22. ''' <param name="pt">
  23. ''' The mouse point.
  24. ''' </param>
  25. ''' ----------------------------------------------------------------------------------------------------
  26. ''' <returns>
  27. ''' The resulting <see cref="Control"/>, or <see langword="Nothing"/>.
  28. ''' </returns>
  29. ''' ----------------------------------------------------------------------------------------------------
  30. Public Shared Function GetControlFromPoint(ByVal container As Control, ByVal pt As Point) As Control
  31.  
  32. Dim child As Control = container
  33. Dim nextChild As Control = Nothing
  34.  
  35. Do While True
  36.  
  37. For Each ctrl As Control In child.Controls
  38. If (ctrl.Visible) AndAlso (ctrl.ClientRectangle.Contains(ctrl.PointToClient(pt))) Then
  39. nextChild = ctrl
  40. Exit For
  41. End If
  42. Next ctrl
  43.  
  44. If (nextChild Is Nothing) Then
  45. If (container.ClientRectangle.Contains(container.PointToClient(pt))) Then
  46. Return container
  47. Else
  48. Return Nothing
  49. End If
  50.  
  51. ElseIf (child.Equals(nextChild)) Then
  52. Exit Do
  53.  
  54. Else
  55. child = nextChild
  56.  
  57. End If
  58.  
  59. Loop
  60.  
  61. Return child
  62.  
  63. End Function
  64.  
  65. ''' ----------------------------------------------------------------------------------------------------
  66. ''' <summary>
  67. ''' Gets the corresponding control (if any) that is over the specified mouse point.
  68. ''' </summary>
  69. ''' ----------------------------------------------------------------------------------------------------
  70. ''' <example> This is a code example.
  71. ''' <code>
  72. ''' Dim ctrl As Control = GetControlFromPoint(Me)
  73. ''' If (ctrl IsNot Nothing) Then
  74. ''' Console.WriteLine(ctrl.Name)
  75. ''' End If
  76. ''' </code>
  77. ''' </example>
  78. ''' ----------------------------------------------------------------------------------------------------
  79. ''' <param name="container">
  80. ''' The source container of controls where to search for.
  81. ''' <para></para>
  82. ''' Normally a <see cref="Form"/>, but you can specify another <see cref="Control"/> that contains a <see cref="ControlCollection"/>.
  83. ''' </param>
  84. ''' ----------------------------------------------------------------------------------------------------
  85. ''' <returns>
  86. ''' The resulting <see cref="Control"/>, or <see langword="Nothing"/>.
  87. ''' </returns>
  88. ''' ----------------------------------------------------------------------------------------------------
  89. Public Shared Function GetControlFromPoint(ByVal container As Control) As Control
  90.  
  91. Return GuiUtil.GetControlFromPoint(container, Cursor.Position)
  92.  
  93. End Function
  94.  
  95. ''' ----------------------------------------------------------------------------------------------------
  96. ''' <summary>
  97. ''' Gets the corresponding control (if any) that is over the specified point.
  98. ''' </summary>
  99. ''' ----------------------------------------------------------------------------------------------------
  100. ''' <example> This is a code example.
  101. ''' <code>
  102. ''' Dim ctrl As Control = GetControlFromPoint(Me, Cursor.Position)
  103. ''' If (ctrl IsNot Nothing) Then
  104. ''' Console.WriteLine(ctrl.Name)
  105. ''' End If
  106. ''' </code>
  107. ''' </example>
  108. ''' ----------------------------------------------------------------------------------------------------
  109. ''' <param name="form">
  110. ''' The source <see cref="Form"/> where to search for.
  111. ''' </param>
  112. '''
  113. ''' <param name="pt">
  114. ''' The mouse point, in non-relative screen coordinates.
  115. ''' </param>
  116. ''' ----------------------------------------------------------------------------------------------------
  117. ''' <returns>
  118. ''' The resulting <see cref="Control"/>, or <see langword="Nothing"/>.
  119. ''' </returns>
  120. ''' ----------------------------------------------------------------------------------------------------
  121. Public Shared Function GetControlFromPoint(ByVal form As Form, ByVal pt As Point) As Control
  122.  
  123. Return GuiUtil.GetControlFromPoint(DirectCast(form, Control), pt)
  124.  
  125. End Function
  126.  
  127. ''' ----------------------------------------------------------------------------------------------------
  128. ''' <summary>
  129. ''' Gets the corresponding control (if any) that is over the current mouse point.
  130. ''' </summary>
  131. ''' ----------------------------------------------------------------------------------------------------
  132. ''' <example> This is a code example.
  133. ''' <code>
  134. ''' Dim ctrl As Control = GetControlFromPoint(Me)
  135. ''' If (ctrl IsNot Nothing) Then
  136. ''' Console.WriteLine(ctrl.Name)
  137. ''' End If
  138. ''' </code>
  139. ''' </example>
  140. ''' ----------------------------------------------------------------------------------------------------
  141. ''' <param name="form">
  142. ''' The source <see cref="Form"/> where to search for.
  143. ''' </param>
  144. ''' ----------------------------------------------------------------------------------------------------
  145. ''' <returns>
  146. ''' The resulting <see cref="Control"/>, or <see langword="Nothing"/>.
  147. ''' </returns>
  148. ''' ----------------------------------------------------------------------------------------------------
  149. Public Shared Function GetControlFromPoint(ByVal form As Form) As Control
  150.  
  151. Return GuiUtil.GetControlFromPoint(DirectCast(form, Control), Cursor.Position)
  152.  
  153. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement