Condividi tramite


Delegato InkCollectorMouseDownEventHandler

Aggiornamento: novembre 2007

Rappresenta il metodo che gestisce l'evento MouseDown di un oggetto InkCollector.

Spazio dei nomi:  Microsoft.Ink
Assembly:  Microsoft.Ink (in Microsoft.Ink.dll)

Sintassi

'Dichiarazione
Public Delegate Sub InkCollectorMouseDownEventHandler ( _
    sender As Object, _
    e As CancelMouseEventArgs _
)
'Utilizzo
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 non supporta i delegati.

Parametri

Note

Quando si crea un delegato InkCollectorMouseDownEventHandler, viene identificato il metodo che gestisce l'evento. Per associare l'evento al gestore in uso, aggiungere all'evento un'istanza del delegato. Il gestore eventi viene chiamato ogni volta che si verifica l'evento, a meno che non si rimuova il delegato. Per motivi di prestazioni, l'interesse dell'evento predefinito è disattivato, ma viene attivato automaticamente nel codice gestito se si aggiunge un gestore eventi.

Per migliorare le prestazioni dell'input penna in tempo reale, nascondere il cursore del mouse durante l'immissione dell'input penna. A tale scopo, nascondere il cursore del mouse nel gestore eventi MouseDown e visualizzarlo nel gestore eventi MouseUp.

Nota

Alcuni controlli si basano su una relazione specifica tra gli eventi MouseDown, MouseMove e MouseUp. L'annullamento di questi eventi può produrre risultati imprevisti.

Esempi

In questo esempio, quando viene generato l'evento MouseDown, viene effettuato un controllo per verificare se l'oggetto EditingMode è impostato su Select. In tal caso, viene chiamato il metodo HitTestSelection per determinare quale parte della selezione (se presente) è stata raggiunta. Se l'occorrenza si verifica in una delle quattro principali direzioni della bussola, come specificato dall'enumerazione SelectionHitResult, gli oggetti di tratto selezionati vengono visualizzati in un altro colore.

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);

    } 
}

Piattaforme

Windows Vista

.NET Framework e .NET Compact Framework non supportano tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema di .NET Framework.

Informazioni sulla versione

.NET Framework

Supportato in: 3.0

Vedere anche

Riferimenti

Spazio dei nomi Microsoft.Ink

InkCollector.MouseMove

InkCollector.MouseUp

InkCollector.MouseWheel