InkOverlay.HitTestSelection Method
Returns a value that indicates which part of a selection, if any, was hit during a hit test.
Namespace: Microsoft.Ink
Assembly: Microsoft.Ink (in Microsoft.Ink.dll)
Syntax
'Declaration
Public Function HitTestSelection ( _
X As Integer, _
Y As Integer _
) As SelectionHitResult
'Usage
Dim instance As InkOverlay
Dim X As Integer
Dim Y As Integer
Dim returnValue As SelectionHitResult
returnValue = instance.HitTestSelection(X, _
Y)
public SelectionHitResult HitTestSelection(
int X,
int Y
)
public:
SelectionHitResult HitTestSelection(
int X,
int Y
)
public function HitTestSelection(
X : int,
Y : int
) : SelectionHitResult
Parameters
X
Type: System.Int32The x-position, in pixels, of the hit test.
Y
Type: System.Int32The y-position, in pixels, of the hit test.
Return Value
Type: Microsoft.Ink.SelectionHitResult
A member of the SelectionHitResult enumeration, which specifies which part of a selection, if any, was hit during a hit test.
Remarks
This method is only useful if the InkOverlay.EditingMode property is set to Select.
Note
When running an ink app on a Windows XP desktop machine that is set to 120dpi, the HitTestSelection method is off by a scaling factor when the point supplied is converted from ink space to pixel space.
Examples
In this example, when the MouseDown event fires, a check is made to see if EditingMode is set to Select. If so, the HitTestSelection method is called to determine which part of the selection (if any) has been hit. If the hit occurs on any of the four main compass directions, as specified by the SelectionHitResult enumeration, the stroke objects that are selected are changed to a different color.
Private Sub mInkObject_MouseDown(ByVal sender As Object, ByVal e As CancelMouseEventArgs)
If InkOverlayEditingMode.Select = mInkObject.EditingMode Then
Select Case mInkObject.HitTestSelection(e.X, e.Y)
Case SelectionHitResult.North
ChangeSelectionColor(Color.Green)
Case SelectionHitResult.East
ChangeSelectionColor(Color.Red)
Case SelectionHitResult.South
ChangeSelectionColor(Color.Purple)
Case SelectionHitResult.West
ChangeSelectionColor(Color.Blue)
End Select
End If
End Sub
Private Sub ChangeSelectionColor(ByVal color As Color)
Dim DA As DrawingAttributes = mInkObject.DefaultDrawingAttributes.Clone()
DA.Color = color
mInkObject.Selection.ModifyDrawingAttributes(DA)
Using G As Graphics = CreateGraphics()
' Get the bounding box of the selection. The default is
' to include the width of the strokes in the calculation.
' The returned rectangle is measured in ink units.
Dim rInkUnits As Rectangle = mInkObject.Selection.GetBoundingBox()
' In selection mode, the selected strokes are drawn inflated
' GetBoundingBox() does not take this into account
' Rectangle rInkUnits is inflated to compensate
rInkUnits.Inflate(53, 53)
Dim topLeft As Point = rInkUnits.Location
Dim bottomRight As Point = rInkUnits.Location + rInkUnits.Size
' get a Renderer object to make the conversion
Dim R As Renderer = New Renderer()
' convert the points to pixels
R.InkSpaceToPixel(G, topLeft)
R.InkSpaceToPixel(G, bottomRight)
' create a rectangle that is in pixels
Dim rPixelUnits As Rectangle = _
New Rectangle(topLeft, New Size(bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y))
' Redraw the strokes
mInkObject.Draw(rPixelUnits)
End Using
End Sub
private void mInkObject_MouseDown(object sender, CancelMouseEventArgs e)
{
if (InkOverlayEditingMode.Select == mInkObject.EditingMode)
{
switch (mInkObject.HitTestSelection(e.X, e.Y))
{
case SelectionHitResult.North:
ChangeSelectionColor(Color.Green);
break;
case SelectionHitResult.East:
ChangeSelectionColor(Color.Red);
break;
case SelectionHitResult.South:
ChangeSelectionColor(Color.Purple);
break;
case SelectionHitResult.West:
ChangeSelectionColor(Color.Blue);
break;
}
}
}
private void ChangeSelectionColor(Color color)
{
DrawingAttributes DA = mInkObject.DefaultDrawingAttributes.Clone();
DA.Color = color;
mInkObject.Selection.ModifyDrawingAttributes(DA);
using (Graphics G = CreateGraphics())
{
// Get the bounding box of the selection. The default is
// to include the width of the strokes in the calculation.
// The returned rectangle is measured in ink units.
Rectangle rInkUnits = mInkObject.Selection.GetBoundingBox();
// In selection mode, the selected strokes are drawn inflated
// GetBoundingBox() does not take this into account
// Rectangle rInkUnits is inflated to compensate
rInkUnits.Inflate(53, 53);
Point topLeft = rInkUnits.Location;
Point bottomRight = rInkUnits.Location + rInkUnits.Size;
// get a Renderer object to make the conversion
Renderer R = new Renderer();
// convert the points to pixels
R.InkSpaceToPixel(G, ref topLeft);
R.InkSpaceToPixel(G, ref bottomRight);
// create a rectangle that is in pixels
Rectangle rPixelUnits =
new Rectangle(topLeft, new Size(bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y));
// Redraw the strokes
mInkObject.Draw(rPixelUnits);
}
}
Platforms
Windows 7, Windows Vista, Windows Server 2008 R2, Windows Server 2008
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information
.NET Framework
Supported in: 3.0