Ink.HitTest 方法 (array<Point[], Single)
返回多边形选择边界所包含的 Strokes 集合。
命名空间: Microsoft.Ink
程序集: Microsoft.Ink(在 Microsoft.Ink.dll 中)
语法
声明
Public Function HitTest ( _
points As Point(), _
percentIntersect As Single _
) As Strokes
用法
Dim instance As Ink
Dim points As Point()
Dim percentIntersect As Single
Dim returnValue As Strokes
returnValue = instance.HitTest(points, _
percentIntersect)
public Strokes HitTest(
Point[] points,
float percentIntersect
)
public:
Strokes^ HitTest(
array<Point>^ points,
float percentIntersect
)
public Strokes HitTest(
Point[] points,
float percentIntersect
)
public function HitTest(
points : Point[],
percentIntersect : float
) : Strokes
参数
- points
类型:array<System.Drawing.Point[]
在选择边界中用于选择 Stroke 对象的点。选择区域是选择边界内的区域,边界在选择边界内首次与自己相交。
- percentIntersect
类型:System.Single
要视为命中而必须包含在选择边界中的笔画点的百分比。
返回值
类型:Microsoft.Ink.Strokes
指定的区域中所包含的 Strokes 集合。
备注
如果选择边界不与自己相交,则 HitTest 方法将一个点添加到数组末尾,从而创建一条从第一个点到最后一个点的直线。如果边界是选择边界之外的直线,则不选择任何 Stroke 对象。
如果点参数为 nullnull 引用(在 Visual Basic 中为 Nothing)(在 Microsoft Visual Basic.NET 中为 Nothing)或包含的点数少于三,则此方法将引发异常。
示例
在此示例中,InkOverlay 中至少 50% 的点位于边界选择内的 Stroke 对象将更改为红色。边界选择点描述一个围绕墨迹控件中心旋转 45 度的矩形。通过使用选择点创建一个 Stroke 对象可使边界选择可见。
Const RadiusPixel As Integer = 120
' get the control. InkOverlay.AttachedControl must be set
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)
' create the boundary points. These points describe a rectangle
' that is rotated around the center 45 degrees (a diamond)
Dim boundaryPts() As Point = _
{ _
New Point(centerPt.X, centerPt.Y - (RadiusPixel / 2)), _
New Point(centerPt.X + (RadiusPixel / 2), centerPt.Y), _
New Point(centerPt.X, centerPt.Y + (RadiusPixel / 2)), _
New Point(centerPt.X - (RadiusPixel / 2), centerPt.Y), _
New Point(centerPt.X, centerPt.Y - (RadiusPixel / 2)) _
}
Using g As Graphics = inkControl.CreateGraphics()
' convert boundary points to ink space coordinates
mInkOverlay.Renderer.PixelToInkSpace(g, boundaryPts)
End Using
' show the tilted rectangle (diamond) by creating a stroke
mInkOverlay.Ink.CreateStroke(boundaryPts)
' Find strokes that are at least 50% inside the boundary points
Dim hitStrokes As Strokes = mInkOverlay.Ink.HitTest(boundaryPts, 50.0F)
' change the strokes that fall inside the boundary points to red
hitStrokes.ModifyDrawingAttributes(New DrawingAttributes(Color.Red))
' invalidate the ink control
inkControl.Invalidate()
const int RadiusPixel = 120;
// get the control. InkOverlay.AttachedControl must be set
Control inkControl = mInkOverlay.AttachedControl;
// get the center of the ink control
Point centerPt = new Point(inkControl.Width / 2, inkControl.Height / 2);
// create the boundary points. These points describe a rectangle
// that is rotated around the center 45 degrees (a diamond)
Point[] boundaryPts = new Point[5]
{
new Point(centerPt.X, centerPt.Y - (RadiusPixel / 2)),
new Point(centerPt.X + (RadiusPixel / 2), centerPt.Y),
new Point(centerPt.X, centerPt.Y + (RadiusPixel / 2)),
new Point(centerPt.X - (RadiusPixel / 2), centerPt.Y),
new Point(centerPt.X, centerPt.Y - (RadiusPixel / 2))
};
using (Graphics g = inkControl.CreateGraphics())
{
// convert boundary points to ink space coordinates
mInkOverlay.Renderer.PixelToInkSpace(g, ref boundaryPts);
}
// show the tilted rectangle (diamond) by creating a stroke
mInkOverlay.Ink.CreateStroke(boundaryPts);
// Find strokes that are at least 50% inside the boundary points
Strokes hitStrokes = mInkOverlay.Ink.HitTest(boundaryPts, 50.0f);
// change the strokes that fall inside the boundary points to red
hitStrokes.ModifyDrawingAttributes(new DrawingAttributes(Color.Red));
// invalidate the ink control
inkControl.Invalidate();
平台
Windows Vista
.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求。
版本信息
.NET Framework
受以下版本支持:3.0