Shape.HitTest Method
Gets information about a line or shape control at the specified position on the screen.
Namespace: Microsoft.VisualBasic.PowerPacks
Assembly: Microsoft.VisualBasic.PowerPacks.Vs (in Microsoft.VisualBasic.PowerPacks.Vs.dll)
Syntax
'Declaration
Public MustOverride Function HitTest ( _
x As Integer, _
y As Integer _
) As Boolean
'Usage
Dim instance As Shape
Dim x As Integer
Dim y As Integer
Dim returnValue As Boolean
returnValue = instance.HitTest(x, y)
public abstract bool HitTest(
int x,
int y
)
public:
virtual bool HitTest(
int x,
int y
) abstract
public abstract function HitTest(
x : int,
y : int
) : boolean
Parameters
x
Type: System.Int32The horizontal screen coordinate.
y
Type: System.Int32The vertical screen coordinate.
Return Value
Type: System.Boolean
true if the line or shape control is located at the specified coordinates; otherwise, false.
Remarks
The x and y parameters represent the current mouse coordinates relative to the screen, not relative to the control's container.
Examples
The following example demonstrates how to use the HitTest method of the LineShape control to determine whether the pointer is positioned over the control when the SPACEBAR is pressed.
Private Sub LineHitTestForm_PreviewKeyDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.PreviewKeyDownEventArgs) _
Handles Me.PreviewKeyDown
If e.KeyCode = Keys.Space Then
Dim px As Integer
Dim py As Integer
Dim hit As Boolean
px = LineHitTestForm.MousePosition.X
py = LineHitTestForm.MousePosition.Y
hit = LineShape1.HitTest(px, py)
MsgBox(CStr(hit))
End If
End Sub
private void LineHitTestForm_PreviewKeyDown(object sender,
System.Windows.Forms.PreviewKeyDownEventArgs e)
{
if (e.KeyCode == Keys.Space)
{
int px;
int py;
bool hit;
string result;
px = LineHitTestForm.MousePosition.X;
py = LineHitTestForm.MousePosition.Y;
hit = lineShape1.HitTest(px, py);
result = hit.ToString();
MessageBox.Show(result);
}
}
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.
See Also
Reference
Microsoft.VisualBasic.PowerPacks Namespace
Other Resources
How to: Draw Lines with the LineShape Control (Visual Studio)
How to: Draw Shapes with the OvalShape and RectangleShape Controls (Visual Studio)