Поделиться через


InkOverlay.NewPackets - событие

Обновлен: Ноябрь 2007

Occurs when the InkOverlay receives packets.

Пространство имен:  Microsoft.Ink
Сборка:  Microsoft.Ink (в Microsoft.Ink.dll)

Синтаксис

'Декларация
Public Event NewPackets As InkCollectorNewPacketsEventHandler
'Применение
Dim instance As InkOverlay
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 не поддерживает события.

Заметки

An InkOverlay object receives packet while a stroke is being collected. Packet events occur rapidly, and a NewPackets event handler must be fast or performance suffers.

The event handler receives an argument of type InkCollectorNewPacketsEventArgs containing data about this event.

When you create an InkCollectorNewPacketsEventHandler delegate, you identify the method that handles the event. To associate the event with your event handler, add an instance of the delegate to the event. The event handler is called whenever the event occurs, unless you remove the delegate. For performance reasons, the default event interest is off but is turned on automatically if you add an event handler.

This event may have an adverse effect on ink performance if too much code is executed in the event handlers.

Примеры

This example demonstrates how you can subscribe to the CursorInRange event, and the NewPackets event obtain ink pressure data, and use that information to manipulate an DrawingAttributes object.

When the CursorInRange event fires, a check is made to see if this is the first time that the InkCollector object has come in contact with this particular Cursor object. If so, the DrawingAttributes property is assigned with a clone of the DefaultDrawingAttributes property. This ensures that subsequent access to the DrawingAttributes property does not throw a null reference exception.

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

When the NewPackets event fires, a check is made to see if NormalPressure is included in the packet data. If so, pressure information is displayed on a status label, and the DrawingAttributes property is modified.

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

Платформы

Windows Vista

Среды .NET Framework и .NET Compact Framework поддерживают не все версии каждой платформы. Поддерживаемые версии перечислены в разделе Требования к системе для .NET Framework.

Сведения о версии

.NET Framework

Поддерживается в версии: 3.0

См. также

Ссылки

InkOverlay Класс

InkOverlay - члены

Microsoft.Ink - пространство имен

Cursor

InkCollectorNewPacketsEventArgs

InkOverlay.DesiredPacketDescription

InkOverlay.NewPackets