Namespace:
System.Windows.Ink
Assembly:
System.Windows (in System.Windows.dll)
Visual Basic (Declaration)
Public Function HitTest ( _
stylusPointCollection As StylusPointCollection _
) As StrokeCollection
Dim instance As StrokeCollection
Dim stylusPointCollection As StylusPointCollection
Dim returnValue As StrokeCollection
returnValue = instance.HitTest(stylusPointCollection)
public StrokeCollection HitTest(
StylusPointCollection stylusPointCollection
)
Consider a StrokeCollection named MyStrokes that contain strokes S0 - S2, and a StylusPointCollection named MySPC that contains points P0 - P3. The following illustration shows the position of these strokes and points.
.png)
If you make the following HitTest call, the returned StrokeCollection contains S1 and S2.
The following code demonstrates the HitTest method. If you draw a stroke that intersects an existing stroke collection, the color of the existing stroke changes to red.
Run this sample
<Canvas>
<Rectangle Height="500" Width="500" Stroke="Black" Margin="50,50,0,0" />
<InkPresenter x:Name="MyIP" Height="500" Width="500" Background="Transparent" Margin="50,50,0,0"
MouseLeftButtonDown="MyIP_MouseLeftButtonDown"
MouseMove="MyIP_MouseMove"
LostMouseCapture="MyIP_LostMouseCapture" />
</Canvas>
Private MyStroke As Stroke
Public Sub New()
MyBase.New()
InitializeComponent()
SetBoundary()
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)
MyIP.CaptureMouse()
Dim MyStylusPointCollection As StylusPointCollection = New StylusPointCollection
MyStylusPointCollection.Add(e.StylusDevice.GetStylusPoints(MyIP))
MyStroke = New Stroke(MyStylusPointCollection)
MyStroke.DrawingAttributes.Color = Colors.Yellow
MyStroke.DrawingAttributes.Width = 8
MyIP.Strokes.Add(MyStroke)
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
MyStroke.StylusPoints.Add(e.StylusDevice.GetStylusPoints(MyIP))
Dim HitStrokes As StrokeCollection = New StrokeCollection
HitStrokes = MyIP.Strokes.HitTest(e.StylusDevice.GetStylusPoints(MyIP))
'Change the color of the strokes that the new strokes intersects with.
Dim i As Integer = 0
Do While (i _
< (HitStrokes.Count - 1))
HitStrokes(i).DrawingAttributes.Color = Colors.Red
i = (i + 1)
Loop
End If
End Sub
'MyStroke is completed
Private Sub MyIP_LostMouseCapture(ByVal sender As Object, ByVal e As MouseEventArgs)
MyStroke = Nothing
End Sub
Stroke MyStroke;
//A new stroke object named MyStroke is created. MyStroke is added to the StrokeCollection of the InkPresenter named MyIP
private void MyIP_MouseLeftButtonDown(object sender, MouseEventArgs e)
{
MyIP.CaptureMouse();
StylusPointCollection MyStylusPointCollection = new StylusPointCollection();
MyStylusPointCollection.Add(e.StylusDevice.GetStylusPoints(MyIP));
MyStroke = new Stroke(MyStylusPointCollection);
MyStroke.DrawingAttributes.Color = Colors.Yellow;
MyStroke.DrawingAttributes.Width = 8;
MyIP.Strokes.Add(MyStroke);
}
//StylusPoint objects are collected from the MouseEventArgs and added to MyStroke.
private void MyIP_MouseMove(object sender, MouseEventArgs e)
{
if (MyStroke != null)
{
MyStroke.StylusPoints.Add(e.StylusDevice.GetStylusPoints(MyIP));
StrokeCollection HitStrokes = new StrokeCollection();
HitStrokes = MyIP.Strokes.HitTest(e.StylusDevice.GetStylusPoints(MyIP));
//Change the color of the strokes that the new strokes intersects with.
for (int i = 0; i < HitStrokes.Count - 1; i++)
{
HitStrokes[i].DrawingAttributes.Color = Colors.Red;
}
}
}
//MyStroke is completed
private void MyIP_LostMouseCapture(object sender, MouseEventArgs e)
{
MyStroke = null;
}
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.
Reference
Other Resources