共用方式為


Stroke.NearestPoint 方法 (Point, Single%)

傳回 Stroke 物件上最接近所指定 (英文) 的位置,以及該點與 Stroke 物件之間的距離。

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

語法

'宣告
Public Function NearestPoint ( _
    pt As Point, _
    <OutAttribute> ByRef distance As Single _
) As Single
'用途
Dim instance As Stroke
Dim pt As Point
Dim distance As Single
Dim returnValue As Single

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

參數

傳回值

型別:System.Single
傳回 Stroke 物件上最接近所指定 (英文) 的位置。

備註

浮點索引是表示 Stroke 物件中兩點之間某個位置的浮點值。舉例來說,如果 0.0 是筆劃的第一點,而 1.0 是筆劃的第二點,0.5 即為第一點和第二點之間的中間處。同樣地,浮點索引值 37.25 則表示筆劃中沿著 37 和 38 兩點間線條上百分之 25 的位置。

範例

在這個範例中,會檢查 InkOverlay 物件的每個已選取的 Stroke 物件。若使用 NearestPoint 方法,則會判斷筆劃上最接近筆墨畫布中心的點,以及從中心到該點的距離 (單位 HIMETRIC)。如果距離至少為 2000 HIMETRIC 單位,則會建立新的 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
' examine each selected stroke
For Each S As Stroke In mInkOverlay.Selection
    ' get the index of the nearest point
    Dim distance As Single
    Dim fIdx As Single = S.NearestPoint(centerPt, distance)
    If distance >= 2000.0 Then
        ' create points from the center to the nearest point on the stroke
        Dim connectPts() As Point = _
        { _
            centerPt, _
            S.GetPoint(CType(Math.Round(fIdx, MidpointRounding.ToEven), Integer)) _
        }
        ' create the stroke
        S.Ink.CreateStroke(connectPts)
    End If
Next
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);
}

// examine each selected stroke
foreach (Stroke S in mInkOverlay.Selection)
{
    // get the index of the nearest point
    float distance;
    float fIdx = S.NearestPoint(centerPt, out distance);
    if (distance >= 2000.0)
    {
        // create points from the center to the nearest point on the stroke
        Point[] connectPts = new Point[2] 
        {
            centerPt, 
            S.GetPoint((int)Math.Round(fIdx, MidpointRounding.ToEven))
        };
        // create the stroke
        S.Ink.CreateStroke(connectPts);
    }
}

平台

Windows Vista

.NET Framework 和 .NET Compact Framework 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱 .NET Framework 系統需求

版本資訊

.NET Framework

支援版本:3.0

請參閱

參考

Stroke 類別

Stroke 成員

NearestPoint 多載

Microsoft.Ink 命名空間

Ink.NearestPoint

Ink.HitTest

Stroke.GetRectangleIntersections