共用方式為


Ink.NearestPoint 方法 (Point, Single%, Single%)

傳回最接近指定點的 Stroke 物件,並傳回 Stroke 物件上最接近指定點的點,同時傳回指定點與 Ink 物件之 Stroke 物件上最接近點間的距離。

命名空間:  Microsoft.Ink
組件:  Microsoft.Ink (在 Microsoft.Ink.dll 中)

語法

'宣告
Public Function NearestPoint ( _
    point As Point, _
    <OutAttribute> ByRef pointOnStroke As Single, _
    <OutAttribute> ByRef distanceFromPacket As Single _
) As Stroke
'用途
Dim instance As Ink
Dim point As Point
Dim pointOnStroke As Single
Dim distanceFromPacket As Single
Dim returnValue As Stroke

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

參數

  • distanceFromPacket
    型別:System.Single%
    指定點與 Ink 物件中最接近之 Stroke 物件間的距離。

傳回值

型別:Microsoft.Ink.Stroke
包含 PointStroke,最接近 Ink 物件中的指定。如果多個筆劃包含的 Point 與已知 Point (英文) 有相同的距離,這個結果的值就是任意值。

備註

distanceFromPacket 參數是描述指定點到 Stroke 物件的封套之間的距離。這是兩個點之間的距離,減去 Stroke 物件 DrawingAttributesWidth 屬性的一半。

範例

在這個範例中,如果 Stroke 物件包含的點位於筆墨控制項中心 500 HIMETRIC 單位內,則 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 distanceFromPacket As Single
Dim nStroke As Stroke = mInkOverlay.Ink.NearestPoint(centerPt, pointOnStroke, distanceFromPacket)
' nStroke will be null if there aren't any strokes
If Not IsNothing(nStroke) And distanceFromPacket <= 500.0 Then
    ' change the color of the nearest stroke to red
    nStroke.DrawingAttributes.Color = Color.Red
    'Dim ptIdx As Integer = DirectCast(Math.Round(pointOnStroke, MidpointRounding.ToEven), Integer)

    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;
float distanceFromPacket;
Stroke nStroke = mInkOverlay.Ink.NearestPoint(centerPt, out pointOnStroke, out distanceFromPacket);

// nStroke will be null if there aren't any strokes
if (nStroke != null && distanceFromPacket <= 500.0)
{
    // 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