InkOverlay.MouseDown 事件
当鼠标指针在 InkOverlay 对象上并且用户按下鼠标按钮时发生。
命名空间: Microsoft.Ink
程序集: Microsoft.Ink(在 Microsoft.Ink.dll 中)
语法
声明
Public Event MouseDown As InkCollectorMouseDownEventHandler
用法
Dim instance As InkOverlay
Dim handler As InkCollectorMouseDownEventHandler
AddHandler instance.MouseDown, handler
public event InkCollectorMouseDownEventHandler MouseDown
public:
event InkCollectorMouseDownEventHandler^ MouseDown {
void add (InkCollectorMouseDownEventHandler^ value);
void remove (InkCollectorMouseDownEventHandler^ value);
}
/** @event */
public void add_MouseDown (InkCollectorMouseDownEventHandler value)
/** @event */
public void remove_MouseDown (InkCollectorMouseDownEventHandler value)
JScript 不支持事件。
备注
事件处理程序接收 CancelMouseEventArgs 类型的参数,该参数包含有关此事件的数据。
创建 InkCollectorMouseDownEventHandler 委托时,需要标识将处理该事件的方法。若要将该事件与事件处理程序关联,请将该委托的一个实例添加到事件中。除非移除了该委托,否则每当发生该事件时就会调用此事件处理程序。出于性能方面的原因,默认事件关注处于关闭状态,但如果添加事件处理程序,它将自动打开。
若要提高实时墨迹性能,请在墨迹书写时隐藏鼠标光标。为此,请在 MouseDown 事件处理程序中隐藏鼠标光标,并在 MouseUp 事件处理程序中显示鼠标光标。
备注
CancelMouseEventArgs 对象的 X 和 Y 属性的单位是像素,而不是与墨迹空间 关联的 HIMETRIC 单位。这是因为此事件替换了不能识别笔的应用程序的相关鼠标事件,并且此类型的应用程序是以像素为单位描述的。
示例
在此示例中,当 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