Ink.NearestPoint 方法 (Point, Single%)

返回离指定点最近的 Stroke 对象,并返回 Stroke 对象上离指定点最近的点。

命名空间:  Microsoft.Ink
程序集:  Microsoft.Ink(在 Microsoft.Ink.dll 中)

语法

声明
Public Function NearestPoint ( _
    point As Point, _
    <OutAttribute> ByRef pointOnStroke As Single _
) As Stroke
用法
Dim instance As Ink
Dim point As Point
Dim pointOnStroke As Single
Dim returnValue As Stroke

returnValue = instance.NearestPoint(point, _
    pointOnStroke)
public Stroke NearestPoint(
    Point point,
    out float pointOnStroke
)
public:
Stroke^ NearestPoint(
    Point point, 
    [OutAttribute] float% pointOnStroke
)
public Stroke NearestPoint(
    Point point,
    /** @attribute OutAttribute */ /** @ref */float pointOnStroke
)
public function NearestPoint(
    point : Point, 
    pointOnStroke : float
) : Stroke

参数

返回值

类型:Microsoft.Ink.Stroke
返回 Stroke,它包含离 Ink 对象中的指定 point 最近的 Point。如果多个笔画 包含与已知 Point 距离相同的 Point,则此结果的值可以是任意的。

备注

pointOnStroke 参数定义为浮点数,这是因为 Stroke 对象上的点可能落在两个物理坐标点之间。例如,值 1.5 表示点落在笔画的第一个和第二个数据包的中间。使用此值调用 Split 方法可以拆分 Stroke 对象,也可以向上或向下舍入该值对 Stroke 对象中的数据包 进行索引。

示例

在此示例中,离墨迹控件中心最近的 Stroke 对象的颜色更改为红色。此外,将创建一个新的 Stroke 对象,该对象从发现的离墨迹控件中心最近的 Stroke 对象直到墨迹控件的中心。

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 pointOnStroke As Single
Dim nStroke As Stroke = mInkOverlay.Ink.NearestPoint(centerPt, pointOnStroke)
' 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
    Dim ptIdx As Integer = CType(Math.Round(pointOnStroke, MidpointRounding.ToEven), Integer)
    ' create points from the center to the nearest point on the stroke
    Dim connectPts() As Point = _
            { _
                centerPt, _
                nStroke.GetPoint(ptIdx) _
            }
    ' create the stroke
    mInkOverlay.Ink.CreateStroke(connectPts)
    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
float pointOnStroke;
Stroke nStroke = mInkOverlay.Ink.NearestPoint(centerPt, out pointOnStroke);

// 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;
    int ptIdx = (int)Math.Round(pointOnStroke, MidpointRounding.ToEven);
    // create points from the center to the nearest point on the stroke
    Point[] connectPts = new Point[2] 
    {
        centerPt, 
        nStroke.GetPoint(ptIdx)
    };
    // create the stroke
    mInkOverlay.Ink.CreateStroke(connectPts);
    inkControl.Invalidate();
}

平台

Windows Vista

.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求

版本信息

.NET Framework

受以下版本支持:3.0

另请参见

参考

Ink 类

Ink 成员

NearestPoint 重载

Microsoft.Ink 命名空间

Stroke

Stroke.Split