Ink.NearestPoint - метод (Point, Single%, Single%)
Обновлен: Ноябрь 2007
Returns the Stroke object nearest a specified point, returns the point on the Stroke object that is closest to the specified point, and returns the distance between the specified point and the nearest point on the Stroke object in the Ink object.
Пространство имен: 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
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.
- distanceFromPacket
Тип: System.Single%
The distance between the specified point and the nearest Stroke object in the Ink object.
Возвращаемое значение
Тип: Microsoft.Ink.Stroke
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 distanceFromPacket parameter describes the distance from the specified point to the envelope of the Stroke object. This is the distance between the two points minus half the Width property of the DrawingAttributes of the Stroke object.
Примеры
In this example, if a Stroke object contains a point that is within 500 HIMETRIC units of the center of the ink control, the color of the Stroke object 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 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