다음을 통해 공유


InkCollectorNewInAirPacketsEventHandler 대리자

업데이트: 2007년 11월

InkCollector 개체의 NewInAirPackets 이벤트를 처리하는 메서드를 나타냅니다.

네임스페이스:  Microsoft.Ink
어셈블리:  Microsoft.Ink(Microsoft.Ink.dll)

구문

‘선언
Public Delegate Sub InkCollectorNewInAirPacketsEventHandler ( _
    sender As Object, _
    e As InkCollectorNewInAirPacketsEventArgs _
)
‘사용 방법
Dim instance As New InkCollectorNewInAirPacketsEventHandler(AddressOf HandlerMethod)
public delegate void InkCollectorNewInAirPacketsEventHandler(
    Object sender,
    InkCollectorNewInAirPacketsEventArgs e
)
public delegate void InkCollectorNewInAirPacketsEventHandler(
    Object^ sender, 
    InkCollectorNewInAirPacketsEventArgs^ e
)
/** @delegate */
public delegate void InkCollectorNewInAirPacketsEventHandler(
    Object sender,
    InkCollectorNewInAirPacketsEventArgs e
)
JScript에서는 대리자를 지원하지 않습니다.

매개 변수

설명

사용자가 펜을 태블릿 근처로 옮길 때 커서가 InkCollector 개체의 창 안에 들어오거나 사용자가 InkCollector 개체에 연결된 창 내에서 마우스를 움직이면 in-air 패킷이 만들어집니다. NewInAirPackets 이벤트는 빠르게 발생하므로 이벤트 처리기의 속도가 느리면 성능이 저하됩니다.

InkCollectorNewInAirPacketsEventHandler 대리자를 만들 때는 이벤트를 처리할 메서드를 식별합니다. 이벤트를 이벤트 처리기와 연결하려면 대리자의 인스턴스를 해당 이벤트에 추가합니다. 대리자를 제거하지 않는 경우 이벤트가 발생할 때마다 이벤트 처리기가 호출됩니다. 이벤트 관심도는 성능상의 이유로 기본적으로 해제되어 있지만 이벤트 처리기를 추가하면 관리 코드에서 자동으로 설정됩니다.

잉크를 삽입하는 경우뿐만 아니라 선택 또는 지우기 모드인 경우에도 NewInAirPackets 이벤트가 발생합니다. 따라서 사용자가 설정하는 편집 모드는 사용자가 직접 모니터링해야 하며 이벤트를 해석하기 전에 모드를 알고 있어야 합니다. 이러한 요구 사항을 적용하면 플랫폼 이벤트를 더 효율적으로 인식하여 플랫폼을 보다 자유롭게 활용할 수 있습니다.

예제

이 C# 예제에서는 in-air 패킷이 사각형 안에 들어오면 폼에 윤곽선이 굵은 사각형을 그리고, 패킷이 사각형을 벗어나면 윤곽선이 좁은 사각형을 그립니다. 이 예제에서는 패킷 이벤트를 사용하여 응용 프로그램 동작을 제어하는 방법을 보여 줍니다.

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
    {
    //...

        InkCollector theInkCollector;
        int indexX, indexY;
        Rectangle rectInterest;
        bool thickBorder;

        public Form1()
        {
            //...

            //Initialize the InkCollector object.
            theInkCollector= new InkCollector(Handle);
            theInkCollector.Enabled = 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
            theInkCollector.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 = theInkCollector.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];
            theInkCollector.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);
        }

        // Event handler for the form's closed event
        private void Form1_Closed(object sender, System.EventArgs e)
        {
            theInkCollector.Dispose();
            theInkCollector= null;
        }
    }
}

이 Microsoft® Visual Basic® .NET 예제에서는 in-air 패킷이 사각형 안에 들어오면 폼에 윤곽선이 굵은 사각형을 그리고, 패킷이 사각형을 벗어나면 윤곽선이 좁은 사각형을 그립니다. 이 예제에서는 패킷 이벤트를 사용하여 응용 프로그램 동작을 제어하는 방법을 보여 줍니다.

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

    Dim theInkCollector As InkCollector
    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 InkCollector object.
        theInkCollector = New InkCollector(Handle)
        theInkCollector.Enabled = 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 theInkCollector.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 = theInkCollector.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

    'Event handler for the form's closed event
    Private Sub Form1_Closed(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Closed
        theInkCollector.Dispose()
        Set theInkCollector = Nothing
    End Sub
End Class

플랫폼

Windows Vista

.NET Framework 및 .NET Compact Framework에서 모든 플랫폼의 전체 버전을 지원하지는 않습니다. 지원되는 버전의 목록을 보려면 .NET Framework 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

3.0에서 지원

참고 항목

참조

Microsoft.Ink 네임스페이스

Cursor

InkCollector.DesiredPacketDescription

InkCollector.NewPackets