Sdílet prostřednictvím


Ink.NearestPoint Method (Point)

Returns the Stroke object within the Ink object that is nearest to a specified Point, given in ink space coordinates.

Namespace:  Microsoft.Ink
Assembly:  Microsoft.Ink (in Microsoft.Ink.dll)

Syntax

'Declaration
Public Function NearestPoint ( _
    point As Point _
) As Stroke
'Usage
Dim instance As Ink 
Dim point As Point 
Dim returnValue As Stroke 

returnValue = instance.NearestPoint(point)
public Stroke NearestPoint(
    Point point
)
public:
Stroke^ NearestPoint(
    Point point
)
public function NearestPoint(
    point : Point
) : Stroke

Parameters

Return Value

Type: Microsoft.Ink.Stroke
The Stroke that contains a Point that is closest to the specified point in the Ink object. If more than one stroke contains a Point that is the same distance from the known Point, the value of this result is arbitrary. If the Ink object contains zero Stroke objects, the return value is nulla null reference (Nothing in Visual Basic) (Nothing in Visual Basic).

Examples

In this example, the color of the Stroke object that is nearest to the center of the ink control is changed to red.

Dim inkControl As Control = mInkOverlay.AttachedControl
' get the center of the ink control 
Dim centerPt As Point = New Point(inkControl.Width / 2, inkControl.Height / 2)
Using g As Graphics = inkControl.CreateGraphics()
    ' convert center point to ink space coordinates
    mInkOverlay.Renderer.PixelToInkSpace(g, centerPt)
End Using 
' get the nearest stroke 
Dim nStroke As Stroke = mInkOverlay.Ink.NearestPoint(centerPt)
' nStroke will be null if there aren't any strokes 
If Not IsNothing(nStroke) Then 
    ' change the color of the nearest stroke to red
    nStroke.DrawingAttributes.Color = Color.Red
    inkControl.Invalidate()
End If
Control inkControl = mInkOverlay.AttachedControl;
// get the center of the ink control
Point centerPt = new Point(inkControl.Width / 2, inkControl.Height / 2);
using (Graphics g = inkControl.CreateGraphics())
{
    // convert center point to ink space coordinates
    mInkOverlay.Renderer.PixelToInkSpace(g, ref centerPt);
}

// get the nearest stroke
Stroke nStroke = mInkOverlay.Ink.NearestPoint(centerPt);

// nStroke will be null if there aren't any strokes 
if (nStroke != null)
{
    // change the color of the nearest stroke to red
    nStroke.DrawingAttributes.Color = Color.Red;
    inkControl.Invalidate();
}

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

See Also

Reference

Ink Class

Ink Members

NearestPoint Overload

Microsoft.Ink Namespace

Stroke

Stroke.Split