Compartir a través de


InkOverlay.MouseDown (Evento)

Actualización: noviembre 2007

Se produce cuando el puntero del mouse está encima del objeto InkOverlay y el usuario presiona un botón del mouse.

Espacio de nombres:  Microsoft.Ink
Ensamblado:  Microsoft.Ink (en Microsoft.Ink.dll)

Sintaxis

'Declaración
Public Event MouseDown As InkCollectorMouseDownEventHandler
'Uso
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 no admite eventos.

Comentarios

El controlador de eventos recibe un argumento de tipo CancelMouseEventArgs que contiene datos sobre este evento.

Cuando se crea un delegado de InkCollectorMouseDownEventHandler, se identifica el método que controla el evento. Para asociarlo al controlador de eventos, se debe agregar al evento una instancia del delegado. Siempre que se produce el evento, se llama a su controlador, a menos que se quite el delegado. Para mejorar el rendimiento, el interés del evento predeterminado está desactivado, pero se activa automáticamente si se agrega un controlador de eventos.

Para mejorar el rendimiento de la entrada manuscrita en tiempo real, oculte el cursor del mouse mientras ésta se lleva a cabo. Para ello, oculte el cursor del mouse en el controlador de eventos MouseDown y muestre el cursor del mouse en el controlador de eventos MouseUp.

Nota

Las propiedades X e Y del objeto CancelMouseEventArgs están expresadas en píxeles y no en las unidades HIMETRIC que están asociadas al espacio de entrada manuscrita. Esto se debe a que este evento reemplaza al evento del mouse relacionado de una aplicación que no reconoce la pluma, y dicho tipo de aplicación se expresa en píxeles.

Nota

Algunos controles se basan en una determinada relación entre los eventos MouseDown, MouseMove y MouseUp. Si se cancela alguno de estos eventos, pueden producirse resultados inesperados.

Ejemplos

En este ejemplo, cuando se desencadena el evento MouseDown, se realiza una comprobación para ver si la propiedad EditingMode está establecida en Select. Si es así, se llama al método HitTestSelection para determinar qué parte de la selección se ha alcanzado (en caso de que haya alguna). Si la posición se encuentra en uno de los cuatro puntos cardinales principales, tal y como especifica la enumeración SelectionHitResult, los objetos del trazo que están seleccionados cambiarán de color.

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

    } 
}

Plataformas

Windows Vista

.NET Framework y .NET Compact Framework no admiten todas las versiones de cada plataforma. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.

Información de versión

.NET Framework

Compatible con: 3.0

Vea también

Referencia

InkOverlay (Clase)

InkOverlay (Miembros)

Microsoft.Ink (Espacio de nombres)

CancelMouseEventArgs

InkOverlay.MouseMove

InkOverlay.MouseUp