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%
Stroke 对象上离 Ink 对象中的指定点最近的点。
- distanceFromPacket
类型:System.Single%
指定点与 Ink 对象中最近的 Stroke 对象之间的距离。
返回值
类型:Microsoft.Ink.Stroke
Stroke ,它包含离 Ink 对象中的指定点最近的 Point。如果多个笔画 包含与已知 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