InkCollectorMouseDownEventHandler 委派
表示處理 InkCollector 物件之 MouseDown 事件的方法。
命名空間: Microsoft.Ink
組件: Microsoft.Ink (在 Microsoft.Ink.dll 中)
語法
'宣告
Public Delegate Sub InkCollectorMouseDownEventHandler ( _
sender As Object, _
e As CancelMouseEventArgs _
)
'用途
Dim instance As New InkCollectorMouseDownEventHandler(AddressOf HandlerMethod)
public delegate void InkCollectorMouseDownEventHandler(
Object sender,
CancelMouseEventArgs e
)
public delegate void InkCollectorMouseDownEventHandler(
Object^ sender,
CancelMouseEventArgs^ e
)
/** @delegate */
public delegate void InkCollectorMouseDownEventHandler(
Object sender,
CancelMouseEventArgs e
)
JScript 不支援委派。
參數
- sender
型別:System.Object
這個事件的來源 InkCollector 物件。
- e
型別:Microsoft.Ink.CancelMouseEventArgs
包含事件資料的 CancelMouseEventArgs 物件。
備註
在建立 InkCollectorMouseDownEventHandler 委派 (Delegate) 時,您會識別處理事件的方法。若要使事件與您的事件處理常式產生關聯,請將委派的執行個體 (Instance) 加入至事件。除非您移除委派,否則每當事件發生時就會呼叫事件處理常式。基於效能考量,相關事件的預設是關閉的,但會在您加入事件處理常式時自動在「Managed 程式碼」中開啟。
若要改善即時筆墨效能,請在使用筆墨書寫時隱藏滑鼠游標。若要執行這項操作,請在 MouseDown 事件處理常式中隱藏滑鼠游標,並且在 MouseUp 事件處理常式中顯示滑鼠游標。
注意事項: |
---|
有些控制項依賴 MouseDown、MouseMove 和 MouseUp 事件之間的特定關聯性 (Relationship)。取消這些事件可能會造成未預期的結果。 |
範例
在這個範例中,當 MouseDown 事件引發時,會檢查 EditingMode 是否設定為 Select。如果是,則會呼叫 HitTestSelection 方法,以判斷選取範圍 (如果有的話) 的哪個部分已被點擊。如果點擊發生於指南針四個主要方向的其中一個 (如 SelectionHitResult 列舉型別 (Enumeration) 所指定),已選取的筆劃物件會變更為不同色彩。
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