업데이트: 2007년 11월
지정된 점에 가장 가까운 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가 들어 있으면 이 결과의 값을 예측할 수 없습니다.
설명
distanceFromPacket 매개 변수는 지정된 점에서 Stroke 개체 엔벌로프까지의 거리를 설명합니다. 이는 두 점 사이의 거리에서 Stroke 개체의 DrawingAttributes에 대한 Width 속성의 절반을 뺀 값에 해당합니다.
예제
이 예제에서는 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에서 지원