Ink.HitTest 方法 (Point, Single)
返回完全在已知圆内或与已知圆相交的 Stroke 对象的 Strokes 集合。
命名空间: Microsoft.Ink
程序集: Microsoft.Ink(在 Microsoft.Ink.dll 中)
语法
声明
Public Function HitTest ( _
point As Point, _
radius As Single _
) As Strokes
用法
Dim instance As Ink
Dim point As Point
Dim radius As Single
Dim returnValue As Strokes
returnValue = instance.HitTest(point, _
radius)
public Strokes HitTest(
Point point,
float radius
)
public:
Strokes^ HitTest(
Point point,
float radius
)
public Strokes HitTest(
Point point,
float radius
)
public function HitTest(
point : Point,
radius : float
) : Strokes
参数
- point
类型:System.Drawing.Point
命中测试圆的中心,采用墨迹空间 坐标。
- radius
类型:System.Single
命中测试圆的半径,采用墨迹空间 坐标。
返回值
类型:Microsoft.Ink.Strokes
指定的区域中所包含的 Strokes 集合。
备注
如果 Stroke 对象与圆相交,则返回完整的 Stroke。
此方法计算相交,考虑应用于 Stroke 对象的完整 DrawingAttributes 集,包括 Width,FitToCurve 属性为 true 还是 false,以及 PenTip 属性的值。
对 Stroke 对象或 Strokes 集合执行旋转或修剪变换后,变换后的 x 和 y 坐标不再与原始坐标具有相同中心。因此,半径参数不应根据 x 或 y 坐标计算。
若要确定已知 Stroke 对象的哪些点与命中测试区域相交,请调用 Stroke.HitTest 方法。
示例
在此示例中,InkOverlay 中与圆心位于墨迹控件中心、半径 120 像素的圆相交的任何 Stroke 对象都将更改为红色。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 rectangle used to draw the circle around the center
Dim hitTestRect As Rectangle = New Rectangle(centerPt.X - RadiusPixel, centerPt.Y - RadiusPixel, RadiusPixel * 2, RadiusPixel * 2)
' get our graphics object
Dim g As Graphics = inkControl.CreateGraphics()
' convert centerPt to ink space coordinates
mInkOverlay.Renderer.PixelToInkSpace(g, centerPt)
' tempPt is used only to convert RadiusPixel to ink coords
Dim tempPt As Point = New Point(RadiusPixel, 0)
mInkOverlay.Renderer.PixelToInkSpace(g, tempPt)
' now tempPt.X = radius in ink coordinates
' Find strokes hit by the circle described by centerPt and radius
Dim hitStrokes As Strokes = mInkOverlay.Ink.HitTest(centerPt, tempPt.X)
' change the strokes that fall inside the circle to red
hitStrokes.ModifyDrawingAttributes(New DrawingAttributes(Color.Red))
' invalidate the ink control
inkControl.Invalidate()
' let the Invalidate message process
Application.DoEvents()
' draw the circle we used for the hit test
g.DrawEllipse(Pens.Blue, hitTestRect)
g.Dispose()
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 rectangle used to draw the circle around the center
Rectangle hitTestRect = new Rectangle(centerPt.X - RadiusPixel, centerPt.Y - RadiusPixel, RadiusPixel * 2, RadiusPixel * 2);
// get our graphics object
Graphics g = inkControl.CreateGraphics();
// convert centerPt to ink space coordinates
mInkOverlay.Renderer.PixelToInkSpace(g, ref centerPt);
// tempPt is used only to convert RadiusPixel to ink coords
Point tempPt = new Point(RadiusPixel, 0);
mInkOverlay.Renderer.PixelToInkSpace(g, ref tempPt);
// now tempPt.X = radius in ink coordinates
// Find strokes hit by the circle described by centerPt and radius
Strokes hitStrokes = mInkOverlay.Ink.HitTest(centerPt, tempPt.X);
// change the strokes that fall inside the circle to red
hitStrokes.ModifyDrawingAttributes(new DrawingAttributes(Color.Red));
// invalidate the ink control
inkControl.Invalidate();
// let the Invalidate message process
Application.DoEvents();
// draw the circle we used for the hit test
g.DrawEllipse(Pens.Blue, hitTestRect);
g.Dispose();
平台
Windows Vista
.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求。
版本信息
.NET Framework
受以下版本支持:3.0