다음을 통해 공유


Ink.NearestPoint Method

Ink.NearestPoint Method

Returns the Stroke object nearest a specified point, returns the point on the Stroke object that is closest to the specified point, and returns the distance between the specified point and the nearest point on the Stroke object in the Ink object.

Definition

Visual Basic .NET Public Function NearestPoint( _
ByVal point As Point, _
ByRef pointOnStroke As Single, _
ByRef distanceFromPacket As Single _
) As Stroke
C# public Stroke NearestPoint(
Point point,
out float pointOnStroke,
out float distanceFromPacket
);
Managed C++ public: Stroke* NearestPoint(
Point *point,
float **pointOnStroke,
float **distanceFromPacket
);

Parameters

point System.Drawing.Point. The specified point within the Ink object, given in ink space coordinates.
pointOnStroke System.Single. The point on the Stroke object that is closest to the specified point within the Ink object.
distanceFromPacket System.Single. The distance between the specified point and the nearest Stroke object in the Ink object.

Return Value

Microsoft.Ink.Stroke. Returns the Stroke that contains a Point Leave Site that is closest to the specified point in the Ink object. If more than one stroke contains a Point Leave Site that is the same distance from the known Point Leave Site, the value of this result is arbitrary.

Exceptions

ObjectDisposedException Leave Site: The Ink object is disposed.

Remarks

The pointOnStroke parameter is defined as a floating-point number because the point on the Stroke object can fall between two physical coordinate points. For example, a value of 1.5 indicates that the point falls halfway between the first and second packets of the stroke. Use this value to split the Stroke object by calling the Stroke.Split method, or round the value up or down to index a packet in the Stroke object.

The distanceFromPacket parameter describes the distance from the specified point to the envelope of the Stroke object. This is the distance between the two points minus half the Width property of the DrawingAttributes of the Stroke object.

Examples

[C#]

This C# example returns the nearest Stroke object to a known Point Leave Site, ptInk, which is given in ink space coordinates. The example also returns the location of the point in the Stroke, thePointInStroke, that is nearest to the specified point and the distance, theDistance, between the specified point and the nearest point on the Stroke object.

float thePointInStroke, theDistance;
Stroke theNearestStroke = theInkCollector.Ink.NearestPoint(ptInk,
    out thePointInStroke, out theDistance);

[Visual Basic .NET]

This Microsoft® Visual Basic® .NET example returns the nearest Stroke object to a known Point Leave Site, ptInk, which is given in ink space coordinates. The example also returns the location of the point in the Stroke, thePointInStroke, that is nearest to the specified point and the distance, theDistance, between the specified point and the nearest point on the Stroke object.

Dim thePointInStroke, theDistance As Single
Dim theNearestStroke As Stroke = theInkCollector.Ink.NearestPoint(ptInk, _
    thePointInStroke, theDistance)

See Also