SimpleShape.HitTest Method (Int32, Int32)

 

Determines whether a shape control is located at the specified point on the screen.

Namespace:   Microsoft.VisualBasic.PowerPacks
Assembly:  Microsoft.VisualBasic.PowerPacks.Vs (in Microsoft.VisualBasic.PowerPacks.Vs.dll)

Syntax

public override bool HitTest(
    int x,
    int y
)
public:
virtual bool HitTest(
    int x,
    int y
) override
override HitTest : 
        x:int *
        y:int -> bool
Public Overrides Function HitTest (
    x As Integer,
    y As Integer
) As Boolean

Parameters

Return Value

Type: System.Boolean

true if the 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 to the control's container.

Examples

The following example demonstrates how to use the HitTest method of the OvalShape control to determine whether the pointer is positioned over the control when the SPACEBAR is pressed.

private void form1_PreviewKeyDown(object sender, 
    System.Windows.Forms.PreviewKeyDownEventArgs e)
{
    if (e.KeyCode == Keys.Space)
    {
        int px;
        int py;
        bool hit;
        string result;
        px = MousePosition.X;
        py = MousePosition.Y;
        hit = ovalShape1.HitTest(px, py);
        result = hit.ToString();
        MessageBox.Show(result);
    }
}
Private Sub Form1_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 = MousePosition.X
        py = MousePosition.Y
        hit = OvalShape1.HitTest(px, py)
        MsgBox(CStr(hit))
    End If
End Sub

See Also

SimpleShape Class
Microsoft.VisualBasic.PowerPacks Namespace
Introduction to the Line and Shape Controls (Visual Studio)
How to: Draw Lines with the LineShape Control (Visual Studio)
How to: Draw Shapes with the OvalShape and RectangleShape Controls (Visual Studio)

Return to top