共用方式為


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 事件處理常式中顯示滑鼠游標。

ms567636.alert_note(zh-tw,VS.90).gif注意事項:

CancelMouseEventArgs 物件的 X 和 Y 屬性使用像素為單位,而不使用與筆墨空間相關聯的 HIMETRIC 單位。這是因為這個事件取代了無畫筆感應之應用程式的相關滑鼠事件,而這一類的應用程式只能是以像素描述。

ms567636.alert_note(zh-tw,VS.90).gif注意事項:

有些控制項依賴 MouseDown、MouseMoveMouseUp 事件之間的特定關聯性。取消其中部分事件可能會造成未預期的結果。

範例

在這個範例中,當 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

請參閱

參考

InkOverlay 類別

InkOverlay 成員

Microsoft.Ink 命名空間

CancelMouseEventArgs

InkOverlay.MouseMove

InkOverlay.MouseUp