共用方式為


InkOverlay.NewInAirPackets 事件

會在 InkOverlay 物件偵測到感應輸入封包時發生。

命名空間:  Microsoft.Ink
組件:  Microsoft.Ink (在 Microsoft.Ink.dll 中)

語法

'宣告
Public Event NewInAirPackets As InkCollectorNewInAirPacketsEventHandler
'用途
Dim instance As InkOverlay
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 不支援事件。

備註

當游標位於 InkOverlay 物件的視窗內時,使用者在手寫板內容的實體偵測範圍 (鄰近) 內移動游標,或在 InkOverlay 物件的相關視窗內移動滑鼠時,便會發生這個事件。

NewInAirPackets 事件的發生速度很快,因此事件處理常式必須很快進行處理,否則效能會受到影響。

事件處理常式會收到 InkCollectorNewInAirPacketsEventArgs 型別的引數,其中包含這個事件的相關資料。

在建立 InkCollectorNewInAirPacketsEventHandler 委派時,您要識別處理事件的方法。若要使事件與您的事件處理常式產生關聯,請將委派的執行個體加入至事件。除非您移除委派,否則每當事件發生時就會呼叫事件處理常式。基於效能考量,相關事件的預設是關閉的,但會在您加入事件處理常式時自動開啟。

並不僅止於插入筆墨時,即使是在選取或清除模式下,也會引發 NewInAirPackets 事件。這會需要您監視編輯模式 (您必須負責其設定),並且在解譯事件之前注意模式。這個需求的優點是透過覺察平台事件,獲得平台創新的更大自由。

範例

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

        InkOverlay theInkOverlay;
        int indexX, indexY;
        Rectangle rectInterest;
        bool thickBorder;

        public Form1()
        {
            //...

            //Initialize the InkOverlay object.
            theInkOverlay= new InkOverlay(Handle);
            theInkOverlay.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
            theInkOverlay.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 = theInkOverlay.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];
            theInkOverlay.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)
        {
            theInkOverlay.Dispose();
            theInkOverlay= null;
        }
    }
}

這個 Microsoft Visual Basic .NET 範例會在感應輸入封包位於矩形內時,於表單上繪製粗外框的矩形,或是在封包位於矩形外時,繪製細外框的矩形。這會示範如何使用封包事件控制應用程式行為。

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

    Dim theInkOverlay As InkOverlay
    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 InkOverlay object.
        theInkOverlay = New InkOverlay(Handle)
        theInkOverlay.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 theInkOverlay.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 = theInkOverlay.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
        theInkOverlay.Dispose()
        Set theInkOverlay = Nothing
    End Sub
End Class

平台

Windows Vista

.NET Framework 和 .NET Compact Framework 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱 .NET Framework 系統需求

版本資訊

.NET Framework

支援版本:3.0

請參閱

參考

InkOverlay 類別

InkOverlay 成員

Microsoft.Ink 命名空間

InkCollectorNewInAirPacketsEventArgs

Cursor

InkOverlay.NewPackets

InkOverlay.DesiredPacketDescription