次の方法で共有


InkCollector.NewInAirPackets イベント

InkCollector オブジェクトが、in-air パケットを検出したときに発生します。

名前空間 :  Microsoft.Ink
アセンブリ :  Microsoft.Ink (Microsoft.Ink.dll 内)

構文

'宣言
Public Event NewInAirPackets As InkCollectorNewInAirPacketsEventHandler
'使用
Dim instance As InkCollector
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 では、イベントは使用できません。

解説

このイベントは、カーソルが InkCollector オブジェクト ウィンドウ内にある場合、またはユーザーがマウスを InkCollector オブジェクトに関連したウィンドウ内で動かした場合に、ユーザーがタブレット コンテキストの物理検出領域 (近接) 内でカーソルを動かしたときに発生します。

NewInAirPackets イベントがすばやく生成されます。またイベント ハンドラも高速である必要があり、そうでなければパフォーマンスに影響が出ます。

イベント ハンドラは、このイベントについてのデータを格納している InkCollectorNewInAirPacketsEventArgs 型の引数を受け取ります。

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

参照

参照

InkCollector クラス

InkCollector メンバ

Microsoft.Ink 名前空間

InkCollectorNewInAirPacketsEventArgs

Cursor

InkCollector.NewPackets

InkCollector.DesiredPacketDescription