InkOverlay.HitTestSelection 方法
返回一个值,该值指示在命中测试过程中命中了所选内容(如果有)的哪个部分。
命名空间: Microsoft.Ink
程序集: Microsoft.Ink(在 Microsoft.Ink.dll 中)
语法
声明
Public Function HitTestSelection ( _
X As Integer, _
Y As Integer _
) As SelectionHitResult
用法
Dim instance As InkOverlay
Dim X As Integer
Dim Y As Integer
Dim returnValue As SelectionHitResult
returnValue = instance.HitTestSelection(X, _
Y)
public SelectionHitResult HitTestSelection(
int X,
int Y
)
public:
SelectionHitResult HitTestSelection(
int X,
int Y
)
public SelectionHitResult HitTestSelection(
int X,
int Y
)
public function HitTestSelection(
X : int,
Y : int
) : SelectionHitResult
参数
- X
类型:System.Int32
命中测试的 x 位置(以像素为单位)。
- Y
类型:System.Int32
命中测试的 y 位置(以像素为单位)。
返回值
类型:Microsoft.Ink.SelectionHitResult
SelectionHitResult 枚举的一个成员,指定在命中测试过程中命中了所选内容(如果有)的哪个部分。
备注
仅当 InkOverlay.EditingMode 属性设置为 Select 时此方法才有用。
备注
当在设置为 120dpi 的 Windows XP 台式计算机上运行墨迹应用程序时,HitTestSelection 方法在提供的点从墨迹空间转换到像素空间时通过比例因子关闭。
示例
在此示例中,当 MouseDown 事件激发时,将检查 EditingMode 是否设置为 Select。如果是,则调用 HitTestSelection 方法来确定已命中哪部分所选内容(如果有)。如果命中发生在由 SelectionHitResult 枚举所指定的四个主要罗盘方向的任一方向上,则所选择的笔画对象更改为另一种颜色。
Private Sub mInkObject_MouseDown(ByVal sender As Object, ByVal e As CancelMouseEventArgs)
If InkOverlayEditingMode.Select = mInkObject.EditingMode Then
Select Case mInkObject.HitTestSelection(e.X, e.Y)
Case SelectionHitResult.North
ChangeSelectionColor(Color.Green)
Case SelectionHitResult.East
ChangeSelectionColor(Color.Red)
Case SelectionHitResult.South
ChangeSelectionColor(Color.Purple)
Case SelectionHitResult.West
ChangeSelectionColor(Color.Blue)
End Select
End If
End Sub
Private Sub ChangeSelectionColor(ByVal color As Color)
Dim DA As DrawingAttributes = mInkObject.DefaultDrawingAttributes.Clone()
DA.Color = color
mInkObject.Selection.ModifyDrawingAttributes(DA)
Using G As Graphics = CreateGraphics()
' Get the bounding box of the selection. The default is
' to include the width of the strokes in the calculation.
' The returned rectangle is measured in ink units.
Dim rInkUnits As Rectangle = mInkObject.Selection.GetBoundingBox()
' In selection mode, the selected strokes are drawn inflated
' GetBoundingBox() does not take this into account
' Rectangle rInkUnits is inflated to compensate
rInkUnits.Inflate(53, 53)
Dim topLeft As Point = rInkUnits.Location
Dim bottomRight As Point = rInkUnits.Location + rInkUnits.Size
' get a Renderer object to make the conversion
Dim R As Renderer = New Renderer()
' convert the points to pixels
R.InkSpaceToPixel(G, topLeft)
R.InkSpaceToPixel(G, bottomRight)
' create a rectangle that is in pixels
Dim rPixelUnits As Rectangle = _
New Rectangle(topLeft, New Size(bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y))
' Redraw the strokes
mInkObject.Draw(rPixelUnits)
End Using
End Sub
private void mInkObject_MouseDown(object sender, CancelMouseEventArgs e)
{
if (InkOverlayEditingMode.Select == mInkObject.EditingMode)
{
switch (mInkObject.HitTestSelection(e.X, e.Y))
{
case SelectionHitResult.North:
ChangeSelectionColor(Color.Green);
break;
case SelectionHitResult.East:
ChangeSelectionColor(Color.Red);
break;
case SelectionHitResult.South:
ChangeSelectionColor(Color.Purple);
break;
case SelectionHitResult.West:
ChangeSelectionColor(Color.Blue);
break;
}
}
}
private void ChangeSelectionColor(Color color)
{
DrawingAttributes DA = mInkObject.DefaultDrawingAttributes.Clone();
DA.Color = color;
mInkObject.Selection.ModifyDrawingAttributes(DA);
using (Graphics G = CreateGraphics())
{
// Get the bounding box of the selection. The default is
// to include the width of the strokes in the calculation.
// The returned rectangle is measured in ink units.
Rectangle rInkUnits = mInkObject.Selection.GetBoundingBox();
// In selection mode, the selected strokes are drawn inflated
// GetBoundingBox() does not take this into account
// Rectangle rInkUnits is inflated to compensate
rInkUnits.Inflate(53, 53);
Point topLeft = rInkUnits.Location;
Point bottomRight = rInkUnits.Location + rInkUnits.Size;
// get a Renderer object to make the conversion
Renderer R = new Renderer();
// convert the points to pixels
R.InkSpaceToPixel(G, ref topLeft);
R.InkSpaceToPixel(G, ref bottomRight);
// create a rectangle that is in pixels
Rectangle rPixelUnits =
new Rectangle(topLeft, new Size(bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y));
// Redraw the strokes
mInkObject.Draw(rPixelUnits);
}
}
平台
Windows Vista
.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求。
版本信息
.NET Framework
受以下版本支持:3.0