Condividi tramite


Evento InkPicture.NewPackets

Aggiornamento: novembre 2007

Si verifica quando il controllo InkPicture riceve i pacchetti.

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

Sintassi

'Dichiarazione
Public Event NewPackets As InkCollectorNewPacketsEventHandler
'Utilizzo
Dim instance As InkPicture
Dim handler As InkCollectorNewPacketsEventHandler

AddHandler instance.NewPackets, handler
public event InkCollectorNewPacketsEventHandler NewPackets
public:
 event InkCollectorNewPacketsEventHandler^ NewPackets {
    void add (InkCollectorNewPacketsEventHandler^ value);
    void remove (InkCollectorNewPacketsEventHandler^ value);
}
/** @event */
public void add_NewPackets (InkCollectorNewPacketsEventHandler value)
/** @event */
public void remove_NewPackets (InkCollectorNewPacketsEventHandler value)
JScript non supporta gli eventi.

Note

Il controllo InkPicture riceve i pacchetti mentre è in corso la raccolta di un tratto. Gli eventi dei pacchetti vengono generati rapidamente e un gestore eventi NewPackets deve essere veloce in modo da non compromettere le prestazioni.

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

Quando si crea un delegato InkCollectorNewPacketsEventHandler, 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 dell'evento 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.

Questo evento può avere un effetto negativo sulle prestazioni dell'input penna se viene eseguito troppo codice nei gestori eventi.

Esempi

In questo esempio viene illustrato come sottoscrivere l'evento CursorInRange, il modo in cui l'evento NewPackets ottiene dati relativi alla pressione dell'input penna e come utilizzare tali informazioni per modificare un oggetto DrawingAttributes.

Quando viene generato l'evento CursorInRange, viene effettuato un controllo per verificare se è la prima volta che l'oggetto InkCollector entra in contatto con questo particolare oggetto Cursor. In questo caso, la proprietà DrawingAttributes viene assegnata con un clone della proprietà DefaultDrawingAttributes. In questo modo viene garantito che l'accesso successivo alla proprietà DrawingAttributes non generi un'eccezione di riferimento null.

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

Quando viene generato l'evento NewPackets, viene effettuato un controllo per verificare se l'oggetto NormalPressure è incluso nei dati del pacchetto. In questo caso, le informazioni sulla pressione vengono visualizzate in un'etichetta di stato e viene modificata la proprietà 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;
        }
    }
}

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

InkPicture Classe

Membri InkPicture

Spazio dei nomi Microsoft.Ink

Cursor

InkCollectorNewPacketsEventArgs

InkPicture.DesiredPacketDescription

InkPicture.NewPackets