Ink.NearestPoint - метод (Point, Single%)
Обновлен: Ноябрь 2007
Returns the Stroke object nearest a specified point, and returns the point on the Stroke object that is closest to the specified point.
Пространство имен: 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
The specified point within the Ink object, given in ink space coordinates.
- pointOnStroke
Тип: System.Single%
The point on the Stroke object that is closest to the specified point within the Ink object.
Возвращаемое значение
Тип: Microsoft.Ink.Stroke
Returns the Stroke that contains a Point that is closest to the specified point in the Ink object. If more than one stroke contains a Point that is the same distance from the known Point, the value of this result is arbitrary.
Заметки
The pointOnStroke parameter is defined as a floating-point number because the point on the Stroke object can fall between two physical coordinate points. For example, a value of 1.5 indicates that the point falls halfway between the first and second packets of the stroke. Use this value to split the Stroke object by calling the Split method, or round the value up or down to index a packet in the Stroke object.
Примеры
In this example, the color of the Stroke object that is nearest to the center of the ink control is changed to red. In addition, a new Stroke object is created that runs from the point of the discovered Stroke object that is closest to the center of the ink control to the center of the ink control.
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