Compartir a través de


InkCollectorMouseDownEventHandler (Delegado)

Actualización: noviembre 2007

Representa el método que controla el evento MouseDown de un objeto InkCollector.

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

Sintaxis

'Declaración
Public Delegate Sub InkCollectorMouseDownEventHandler ( _
    sender As Object, _
    e As CancelMouseEventArgs _
)
'Uso
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 no admite delegados.

Parámetros

Comentarios

Al crear 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. Por motivos de rendimiento, el interés del evento predeterminado está desactivado, pero se activa automáticamente en código administrado si se agrega un controlador de eventos.

Para mejorar el rendimiento de la entrada manuscrita en tiempo real, oculte el cursor del mouse mientras se está llevando 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

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

Ejemplos

En este ejemplo, cuando el evento MouseDown se desencadena, se realiza una comprobación para ver si EditingMode está establecido 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

Microsoft.Ink (Espacio de nombres)

InkCollector.MouseMove

InkCollector.MouseUp

InkCollector.MouseWheel