Condividi tramite


Evento InkOverlay.MouseDown

Aggiornamento: novembre 2007

Si verifica quando il puntatore del mouse si trova sull'oggetto InkOverlay e l'utente preme un pulsante del mouse.

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

Sintassi

'Dichiarazione
Public Event MouseDown As InkCollectorMouseDownEventHandler
'Utilizzo
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 non supporta gli eventi.

Note

Il gestore eventi riceve un argomento di tipo CancelMouseEventArgs contenente i dati relativi a questo evento.

Quando si crea un delegato InkCollectorMouseDownEventHandler, si identifica 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 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

Le proprietà X e Y dell'oggetto CancelMouseEventArgs sono espresse in pixel, non in unità HIMETRIC associate allo spazio di input penna. Ciò è dovuto al fatto che questo evento sostituisce l'evento del mouse correlato di un'applicazione che non è in grado di riconoscere l'input penna e che tale tipo di applicazione è rappresentato in pixel.

Nota

Alcuni controlli si basano su una relazione specifica tra gli eventi MouseDown, MouseMove e MouseUp. L'annullamento di alcuni di questi eventi può avere 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

InkOverlay Classe

Membri InkOverlay

Spazio dei nomi Microsoft.Ink

CancelMouseEventArgs

InkOverlay.MouseMove

InkOverlay.MouseUp