Stroke.HitTest Method


Indicates whether a specified StylusPointCollection intersects with a Stroke object.

Namespace:  System.Windows.Ink
Assembly:  System.Windows (in System.Windows.dll)

Public Function HitTest ( _
	stylusPointCollection As StylusPointCollection _
) As Boolean


Type: System.Windows.Input.StylusPointCollection
The StylusPointCollection used to check for intersection with the Stroke object.

Return Value

Type: System.Boolean
true if the specified StylusPointCollection intersects with the Stroke object; otherwise, false.

The following code demonstrates the HitTest method. If you draw a stroke that intersects an existing stroke, the color of the existing stroke changes to red.

Run this sample

    Private MyStroke As Stroke

    Public Sub New()
    End Sub

    'A new stroke object, MyStroke, is created and is added to the StrokeCollection object
    'of the InkPresenter, MyIP
    Private Sub MyIP_MouseLeftButtonDown(ByVal sender As Object, ByVal e As MouseEventArgs)
        Dim MyStylusPointCollection As StylusPointCollection = New StylusPointCollection
        MyStroke = New Stroke(MyStylusPointCollection)
        MyStroke.DrawingAttributes.Color = Colors.Yellow
        MyStroke.DrawingAttributes.Width = 8
    End Sub

    'StylusPoint objects are collected from the MouseEventArgs and added to MyStroke. 
    Private Sub MyIP_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)
        If (Not (MyStroke) Is Nothing) Then
            'Iterate through the stroke collection
            Dim i As Integer = 0
            Do While (i _
                        < (MyIP.Strokes.Count - 1))
                Dim HitStroke As Stroke = MyIP.Strokes(i)
                'If the new stroke intersects with an existing stroke, the color of the 
                'existing stroke is changed to red.
                If HitStroke.HitTest(e.StylusDevice.GetStylusPoints(MyIP)) Then
                    HitStroke.DrawingAttributes.Color = Colors.Red
                End If
                i = (i + 1)
        End If
    End Sub

    'MyStroke is completed
    Private Sub MyIP_LostMouseCapture(ByVal sender As Object, ByVal e As MouseEventArgs)
        MyStroke = Nothing
    End Sub


Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.