Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
HitTestSelection Method

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)

public SelectionHitResult HitTestSelection(
	int X,
	int Y


Type: System.Int32

The x-position, in pixels, of the hit test.

Type: System.Int32

The 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.

This method is only useful if the InkOverlay.EditingMode property is set to Select.


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.

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 void mInkObject_MouseDown(object sender, CancelMouseEventArgs e)
    if (InkOverlayEditingMode.Select == mInkObject.EditingMode)
        switch (mInkObject.HitTestSelection(e.X, e.Y))
            case SelectionHitResult.North:
            case SelectionHitResult.East:
            case SelectionHitResult.South:
            case SelectionHitResult.West:

private void ChangeSelectionColor(Color color)
    DrawingAttributes DA = mInkObject.DefaultDrawingAttributes.Clone();
    DA.Color = color;
    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


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.

.NET Framework

Supported in: 3.0

Community Additions

© 2015 Microsoft