Share via


InkPicture.NewInAirPackets (Evento)

Actualización: noviembre 2007

Se produce cuando el control InkPicture detecta un paquete en el aire.

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

Sintaxis

'Declaración
Public Event NewInAirPackets As InkCollectorNewInAirPacketsEventHandler
'Uso
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 no admite eventos.

Comentarios

Este evento se produce cuando un usuario mueve un cursor dentro del intervalo de detección físico (proximidad) del contexto del Tablet PC mientras el cursor está dentro de la ventana del control InkPicture o el usuario mueve un mouse dentro de la ventana asociada del control InkPicture.

Los eventos NewInAirPackets se generan rápidamente y el controlador de eventos debe ser rápido o se reduce el rendimiento

El controlador de eventos recibe un argumento de tipo InkCollectorNewInAirPacketsEventArgs que contiene datos sobre este evento.

Cuando se crea un delegado de InkCollectorNewInAirPacketsEventHandler, 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 si se agrega un controlador de eventos.

El evento NewInAirPackets se desencadena incluso cuando se está en modo de selección o borrado, no sólo cuando se está en modo de entrada manuscrita. Esto requiere que supervise el modo de edición (de cuya configuración es responsable) y que preste atención a este modo antes de interpretar el evento. La ventaja de este requisito es que se tiene mayor libertad para innovar en la plataforma gracias a un mejor conocimiento de los eventos de la misma.

Ejemplos

En este ejemplo de C# se dibuja un rectángulo en un control InkPicture, theInkPicture. El controlador de eventos NewInAirPackets perfila el rectángulo con un contorno en negrita cuando theInkPicture detecta paquetes en el aire dentro de los límites del rectángulo y con un contorno estrecho cuando theInkPicture detecta paquetes en el aire fuera de los límites del rectángulo. Aquí se muestra cómo se utilizan los eventos de paquete para controlar el comportamiento de la aplicación.

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

En este ejemplo de Microsoft® Visual Basic® .NET el controlador de eventos perfila el rectángulo con un contorno en negrita cuando theInkPicture detecta paquetes en el aire dentro de los límites del rectángulo y con un contorno estrecho cuando theInkPicture detecta paquetes en el aire fuera de los límites del rectángulo. Aquí se muestra cómo se utilizan los eventos de paquete para controlar el comportamiento de la aplicación.

[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

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

InkPicture (Clase)

InkPicture (Miembros)

Microsoft.Ink (Espacio de nombres)

Cursor

InkCollectorNewInAirPacketsEventArgs

InkPicture.DesiredPacketDescription

InkPicture.NewPackets