次の方法で共有


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

パラメータ

  • point
    型 : System.Drawing.Point
    インク空間座標内で指定された Ink オブジェクト内にある指定されたポイント。
  • pointOnStroke
    型 : System.Single%
    Ink オブジェクト内で指定されたポイントに最も近い Stroke オブジェクトのポイント。
  • distanceFromPacket
    型 : System.Single%
    指定されたポイントから、Ink オブジェクト内の最も近い Stroke オブジェクトまでの距離。

戻り値

型 : Microsoft.Ink.Stroke
Ink オブジェクト内の指定されたポイントに最も近い Point を含む Stroke。既知の Point からの距離が同じである Point が 1 つ以上のストロークに含まれている場合、この結果値は任意になります。

解説

distanceFromPacket パラメータは、指定されたポイントから Stroke オブジェクトのエンベロープまでの距離を記述します。これは、2 つのポイント間の距離から Stroke オブジェクトの DrawingAttributesWidth プロパティの 1/2 を引いたものです。

この例では、インク コントロールの中心から 500 HIMETRIC 単位以内にあるポイントが 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 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