Share via


InkCollectorNewPacketsEventHandler (Delegado)

Actualización: noviembre 2007

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

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

Sintaxis

'Declaración
Public Delegate Sub InkCollectorNewPacketsEventHandler ( _
    sender As Object, _
    e As InkCollectorNewPacketsEventArgs _
)
'Uso
Dim instance As New InkCollectorNewPacketsEventHandler(AddressOf HandlerMethod)
public delegate void InkCollectorNewPacketsEventHandler(
    Object sender,
    InkCollectorNewPacketsEventArgs e
)
public delegate void InkCollectorNewPacketsEventHandler(
    Object^ sender, 
    InkCollectorNewPacketsEventArgs^ e
)
/** @delegate */
public delegate void InkCollectorNewPacketsEventHandler(
    Object sender,
    InkCollectorNewPacketsEventArgs e
)
JScript no admite delegados.

Parámetros

Comentarios

Cuando se crea un delegado de InkCollectorNewPacketsEventHandler, 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 en código administrado si se agrega un controlador de eventos.

Se reciben los paquetes mientras se recolecta un trazo. Los eventos de paquete se producen rápidamente y un controlador de eventos NewPackets debe ser rápido, porque si no se reduce el rendimiento de la entrada manuscrita.

Ejemplos

En este ejemplo se muestra cómo se puede suscribir al evento CursorInRange, y cómo el evento NewPackets obtiene los datos de la presión de la entrada manuscrita y utiliza dicha información para manipular un objeto DrawingAttributes.

Cuando se desencadena el evento CursorInRange, se realiza una comprobación para evaluar si se trata de la primera vez que el objeto InkCollector ha entrado en contacto con este objeto Cursor específico. En caso afirmativo, a la propiedad DrawingAttributes se le asigna un clon de la propiedad DefaultDrawingAttributes. De este modo, se garantiza que el acceso posterior a la propiedad DrawingAttributes no desencadene una excepción de referencia nula.

Private Sub mInkObject_CursorInRange(ByVal sender As Object, ByVal e As InkCollectorCursorInRangeEventArgs)
    Const MOUSE_CURSOR_ID As Integer = 1
    If e.NewCursor Then
        ' mInkObject can be InkCollector, InkOverlay, or InkPicture
        e.Cursor.DrawingAttributes = mInkObject.DefaultDrawingAttributes.Clone()
        ' if this cursor is the mouse, we'll set color to red
        If (MOUSE_CURSOR_ID = e.Cursor.Id) Then
            e.Cursor.DrawingAttributes.Color = Color.Red
        End If

    End If
End Sub
private void mInkObject_CursorInRange(object sender, InkCollectorCursorInRangeEventArgs e)
{
    const int MOUSE_CURSOR_ID = 1;

    if (e.NewCursor)
    {
        // mInkObject can be InkCollector, InkOverlay, or InkPicture
        e.Cursor.DrawingAttributes = mInkObject.DefaultDrawingAttributes.Clone();
        // if this cursor is the mouse, we'll set color to red
        if (MOUSE_CURSOR_ID == e.Cursor.Id)
        {
            e.Cursor.DrawingAttributes.Color = Color.Red;
        }
    }
}

Cuando se desencadena el evento NewPackets, se realiza una comprobación para evaluar si se incluye el campo NormalPressure en los datos del paquete. En caso afirmativo, la información sobre la presión se muestra en una etiqueta de estado y se modifica la propiedad DrawingAttributes.

Private Sub mInkObject_NewPackets(ByVal sender As Object, ByVal e As InkCollectorNewPacketsEventArgs)

    ' find the NormalPressure PacketProperty
    ' Set NormalPressure to -1 if not there, as some digitizers won't support it
    Dim PacketDesc As Guid() = e.Stroke.PacketDescription
    Dim NormalPressure As Integer = -1

    For k As Integer = 0 To PacketDesc.Length - 1
        If PacketDesc(k) = PacketProperty.NormalPressure Then
            ' for simplicity, in case of multiple packets, use the first packet only
            NormalPressure = e.PacketData(k)
        End If
    Next k

    ' If we have the NormalPressure information
    ' change DrawingAttributes according to the NormalPressure
    ' Note that the change does not take effect until the next stroke
    If NormalPressure <> -1 Then
        ' display the pressure on a status label
        Me.statusLabelPressure.Text = NormalPressure.ToString()
        e.Cursor.DrawingAttributes.Width = NormalPressure * 4
        ' if pressure is above 127, change color to Red
        If NormalPressure > 127 Then
            e.Cursor.DrawingAttributes.Color = Color.Red
        Else
            e.Cursor.DrawingAttributes.Color = mInkObject.DefaultDrawingAttributes.Color
        End If
    End If

End Sub
private void mInkObject_NewPackets(object sender, InkCollectorNewPacketsEventArgs e)
{
    // find the NormalPressure PacketProperty
    // Set NormalPressure to -1 if not there, as some digitizers won't support it
    Guid[] PacketDesc = e.Stroke.PacketDescription;
    int NormalPressure = -1;
    for (int k = 0; k < PacketDesc.Length; k++)
    {
        if (PacketDesc[k] == PacketProperty.NormalPressure)
        {
            // for simplicity, in case of multiple packets, use the first packet only
            NormalPressure = e.PacketData[k];
        }
    }

    // If we have the NormalPressure information
    // change DrawingAttributes according to the NormalPressure
    // Note that the change does not take effect until the next stroke
    if (NormalPressure != -1)
    {
        // display the pressure on a status label
        this.statusLabelPressure.Text = NormalPressure.ToString();
        e.Cursor.DrawingAttributes.Width = NormalPressure * 4;
        // if pressure is above 127, change color to Red
        if (NormalPressure > 127)
        {
            e.Cursor.DrawingAttributes.Color = Color.Red;
        }
        else
        {
            e.Cursor.DrawingAttributes.Color = mInkObject.DefaultDrawingAttributes.Color;
        }
    }
}

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)

Cursor

InkCollectorNewInAirPacketsEventHandler

Stroke