업데이트: 2007년 11월
지정된 점에 가장 가까운 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
매개 변수
- point
형식: System.Drawing.Point
Ink 개체 내의 잉크 공간 좌표로 지정된 점입니다.
- pointOnStroke
형식: System.Single%
Ink 개체 내의 지정된 점에 가장 가까운 Stroke 개체의 점입니다.
반환 값
형식: Microsoft.Ink.Stroke
Ink 개체의 지정된 point에 가장 가까운 Point가 들어 있는 Stroke를 반환합니다. 둘 이상의 스트로크에 알려진 Point와 거리가 같은 Point가 들어 있으면 이 결과의 값을 예측할 수 없습니다.
설명
Stroke 개체의 점이 두 물리적 좌표 점 사이에 위치할 수 있기 때문에 pointOnStroke 매개 변수는 부동 소수점 숫자로 정의됩니다. 예를 들어 값이 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에서 지원