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


InkPicture.NewInAirPackets - событие

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

Occurs when the InkPicture control detects an in-air packet.

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

Синтаксис

'Декларация
Public Event NewInAirPackets As InkCollectorNewInAirPacketsEventHandler
'Применение
Dim instance As InkPicture
Dim handler As InkCollectorNewInAirPacketsEventHandler

AddHandler instance.NewInAirPackets, handler
public event InkCollectorNewInAirPacketsEventHandler NewInAirPackets
public:
 event InkCollectorNewInAirPacketsEventHandler^ NewInAirPackets {
    void add (InkCollectorNewInAirPacketsEventHandler^ value);
    void remove (InkCollectorNewInAirPacketsEventHandler^ value);
}
/** @event */
public void add_NewInAirPackets (InkCollectorNewInAirPacketsEventHandler value)
/** @event */
public void remove_NewInAirPackets (InkCollectorNewInAirPacketsEventHandler value)
JScript не поддерживает события.

Заметки

This event occurs when a user moves a cursor within the physical detection range (proximity) of the tablet context while the cursor is within the InkPicture control's window or the user moves a mouse within the InkPicture control's associated window.

NewInAirPackets events are generated rapidly, and the event handler must be fast or performance suffers

The event handler receives an argument of type InkCollectorNewInAirPacketsEventArgs that contains data about this event.

When you create an InkCollectorNewInAirPacketsEventHandler 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.

The NewInAirPackets event fires even when in select or erase mode, not only when inserting ink. This requires that you monitor the editing mode (which you are responsible for setting) and be aware of the mode before interpreting the event. The advantage of this requirement is greater freedom to innovate on the platform through greater awareness of platform events.

Примеры

This C# example draws a rectangle on an InkPicture control, theInkPicture. The NewInAirPackets event handler outlines the rectangle with a bold outline when theInkPicture detects in-air packets within the bounds of the rectangle and with a narrow outline when theInkPicture detects in-air packets outside the bounds of the rectangle. This demonstrates how to use the packet events to control application behaviors.

[C#]

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.Ink;

namespace CSInAirPacketEvents
{
    public class Form1 : System.Windows.Forms.Form
    {
    //...

        int indexX, indexY;
        Rectangle rectInterest;
        bool thickBorder;

        public Form1()
        {
            //...

            //Initialize the InkPicture control.
            theInkPicture.InkEnabled = true;

            //Initialize the target rectangle
            rectInterest = new Rectangle(40, 40, 200, 80);
            thickBorder = false;

            //Save the X and Y data locations within the packet data.
            GetXYIndexes(ref indexX, ref indexY);

            //Add the event handler for in-air packets
            theInkPicture.NewInAirPackets += new InkCollectorNewInAirPacketsEventHandler(NewInAirPackets_Event);
        }

//...

        private void GetXYIndexes(ref int theXIndex, ref int theYIndex)
        {
            // Get the indexes of the X and Y data within the raw
            // packet data array.
            Guid [] theGuids = theInkPicture.DesiredPacketDescription;
            for (int i = 0; i < theGuids.Length; i++)
            {
                if (theGuids[i].Equals(PacketProperty.X))
                    theXIndex = i;
                if (theGuids[i].Equals(PacketProperty.Y))
                    theYIndex = i;
            }
        }

        private void NewInAirPackets_Event(object sender, InkCollectorNewInAirPacketsEventArgs e)
        {
            Graphics g = this.CreateGraphics();
            Point [] pt = new Point [1];
            pt[0].X = e.PacketData[indexX];
            pt[0].Y = e.PacketData[indexY];
            theInkPicture.Renderer.InkSpaceToPixel(g, ref pt);

            // The event may return with data for multiple packets.
            // To simplify things, we'll only look at the first.
            if (rectInterest.Contains(pt[0].X, pt[0].Y))
            {
                if (!thickBorder)
                {
                    thickBorder = true;
                    Refresh();
                }
            }
            else
            {
                if (thickBorder)
                {
                    thickBorder = false;
                    Refresh();
                }
            }
        }

        private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Pen thePen = new Pen(Color.Black, 2);
            if (thickBorder)
                thePen.Width = 5;
            g.DrawRectangle(thePen, rectInterest);
        }
    }
}

This Microsoft® Visual Basic® .NET event handler outlines the rectangle with a bold outline when theInkPicture detects in-air packets within the bounds of the rectangle and with a narrow outline when theInkPicture detects in-air packets outside the bounds of the rectangle. This demonstrates how to use the packet events to control application behaviors.

[Visual Basic]

Imports Microsoft.Ink
Public Class Form1
    Inherits System.Windows.Forms.Form

    Dim indexX, indexY As Integer
    Dim rectInterest As Rectangle
    Dim thickBorder As Boolean

'...

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Initialize the InkPicture control.
        theInkPicture.InkEnabled = True

        'Initialize the target rectangle
        rectInterest = New Rectangle(40, 40, 200, 80)
        thickBorder = False

        'Save the X and Y data locations within the packet data.
        GetXYIndexes(indexX, indexY)

        'Add the event handler for in air packets
        AddHandler theInkPicture.NewInAirPackets, AddressOf NewInAirPackets_Event

    End Sub

'...

    Private Sub GetXYIndexes(ByRef theXIndex As Integer, _
        ByRef theYIndex As Integer)
        ' Get the indexes of the X and Y data within the raw
        ' packet data array.
        Dim theGuids() As Guid = theInkPicture.DesiredPacketDescription
        Dim i As Integer
        For i = 0 To theGuids.Length - 1
            If theGuids(i).Equals(PacketProperty.X) Then
                theXIndex = i
            End If
            If theGuids(i).Equals(PacketProperty.Y) Then
                theYIndex = i
            End If
        Next
    End Sub

    Private Sub NewInAirPackets_Event(ByVal sender As Object, _
        ByVal e As InkCollectorNewInAirPacketsEventArgs)
        'The event may return with data for multiple packets.
        'To simplify things, we'll only look at the first.
        If rectInterest.Contains( _
            e.PacketData(indexX), e.PacketData(indexY)) Then
            If thickBorder = False Then
                thickBorder = True
                Refresh()
            End If
        Else
            If thickBorder = True Then
                thickBorder = False
                Refresh()
            End If
        End If
    End Sub

    Private Sub Form1_Paint(ByVal sender As Object, _
        ByVal e As System.Windows.Forms.PaintEventArgs) _
        Handles MyBase.Paint
        Dim g As Graphics = e.Graphics
        Dim thePen As New Pen(Color.Black, 2)
        If thickBorder Then
            thePen.Width = 5
        End If
        g.DrawRectangle(thePen, rectInterest)
    End Sub

End Class

Платформы

Windows Vista

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

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

.NET Framework

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

См. также

Ссылки

InkPicture Класс

InkPicture - члены

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

Cursor

InkCollectorNewInAirPacketsEventArgs

InkPicture.DesiredPacketDescription

InkPicture.NewPackets