次の方法で共有


InkPicture.NewPackets イベント

InkPicture コントロールがパケットを受信すると発生します。

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

構文

'宣言
Public Event NewPackets As InkCollectorNewPacketsEventHandler
'使用
Dim instance As InkPicture
Dim handler As InkCollectorNewPacketsEventHandler

AddHandler instance.NewPackets, handler
public event InkCollectorNewPacketsEventHandler NewPackets
public:
 event InkCollectorNewPacketsEventHandler^ NewPackets {
    void add (InkCollectorNewPacketsEventHandler^ value);
    void remove (InkCollectorNewPacketsEventHandler^ value);
}
/** @event */
public void add_NewPackets (InkCollectorNewPacketsEventHandler value)
/** @event */
public void remove_NewPackets (InkCollectorNewPacketsEventHandler value)
JScript では、イベントは使用できません。

解説

InkPicture コントロールは、ストロークの収集中にパケットを受信します。パケット イベントがすばやく発生します。また NewPackets イベント ハンドラも高速である必要があり、そうでない場合はパフォーマンスに影響が出ます。

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

InkCollectorNewPacketsEventHandler デリゲートを作成する場合は、イベントを処理するメソッドを指定します。イベントをイベント ハンドラに関連付けるには、デリゲートのインスタンスをイベントに追加します。デリゲートを削除しない限り、そのイベントが発生すると常にイベント ハンドラが呼び出されます。パフォーマンス上の理由から、既定のイベント対象は無効ですが、イベント ハンドラを追加すると、自動的に有効になります。

このイベントは、イベント ハンドラで実行されるコードが多すぎる場合に、インクのパフォーマンスに悪影響を与える可能性があります。

この例では、CursorInRange イベントおよび NewPackets イベントにサブスクライブし、インク圧力データを取得し、その情報を使用して DrawingAttributes オブジェクトを操作する方法を示します。

CursorInRange イベントが発生するときに、InkCollector オブジェクトがこの特定の Cursor オブジェクトとやり取りを行ったのがこれが初めてであるかどうかを確認するチェックが行われます。初めてである場合は、DefaultDrawingAttributes プロパティの複製を使用して、DrawingAttributes プロパティが割り当てられます。これにより、以降の DrawingAttributes プロパティへのアクセスで、Null 参照例外がスローされなくなります。

Private Sub mInkObject_CursorInRange(ByVal sender As Object, ByVal e As InkCollectorCursorInRangeEventArgs)
    Const MOUSE_CURSOR_ID As Integer = 1
    If e.NewCursor Then
        ' mInkObject can be InkCollector, InkOverlay, or InkPicture
        e.Cursor.DrawingAttributes = mInkObject.DefaultDrawingAttributes.Clone()
        ' if this cursor is the mouse, we'll set color to red
        If (MOUSE_CURSOR_ID = e.Cursor.Id) Then
            e.Cursor.DrawingAttributes.Color = Color.Red
        End If

    End If
End Sub
private void mInkObject_CursorInRange(object sender, InkCollectorCursorInRangeEventArgs e)
{
    const int MOUSE_CURSOR_ID = 1;

    if (e.NewCursor)
    {
        // mInkObject can be InkCollector, InkOverlay, or InkPicture
        e.Cursor.DrawingAttributes = mInkObject.DefaultDrawingAttributes.Clone();
        // if this cursor is the mouse, we'll set color to red
        if (MOUSE_CURSOR_ID == e.Cursor.Id)
        {
            e.Cursor.DrawingAttributes.Color = Color.Red;
        }
    }
}

NewPackets イベントが発生するときに、NormalPressure がパケット データに含まれているかどうかを確認するチェックが行われます。含まれている場合、圧力情報がステータス ラベルに表示され、DrawingAttributes プロパティが変更されます。

Private Sub mInkObject_NewPackets(ByVal sender As Object, ByVal e As InkCollectorNewPacketsEventArgs)

    ' find the NormalPressure PacketProperty
    ' Set NormalPressure to -1 if not there, as some digitizers won't support it
    Dim PacketDesc As Guid() = e.Stroke.PacketDescription
    Dim NormalPressure As Integer = -1

    For k As Integer = 0 To PacketDesc.Length - 1
        If PacketDesc(k) = PacketProperty.NormalPressure Then
            ' for simplicity, in case of multiple packets, use the first packet only
            NormalPressure = e.PacketData(k)
        End If
    Next k

    ' If we have the NormalPressure information
    ' change DrawingAttributes according to the NormalPressure
    ' Note that the change does not take effect until the next stroke
    If NormalPressure <> -1 Then
        ' display the pressure on a status label
        Me.statusLabelPressure.Text = NormalPressure.ToString()
        e.Cursor.DrawingAttributes.Width = NormalPressure * 4
        ' if pressure is above 127, change color to Red
        If NormalPressure > 127 Then
            e.Cursor.DrawingAttributes.Color = Color.Red
        Else
            e.Cursor.DrawingAttributes.Color = mInkObject.DefaultDrawingAttributes.Color
        End If
    End If

End Sub
private void mInkObject_NewPackets(object sender, InkCollectorNewPacketsEventArgs e)
{
    // find the NormalPressure PacketProperty
    // Set NormalPressure to -1 if not there, as some digitizers won't support it
    Guid[] PacketDesc = e.Stroke.PacketDescription;
    int NormalPressure = -1;
    for (int k = 0; k < PacketDesc.Length; k++)
    {
        if (PacketDesc[k] == PacketProperty.NormalPressure)
        {
            // for simplicity, in case of multiple packets, use the first packet only
            NormalPressure = e.PacketData[k];
        }
    }

    // If we have the NormalPressure information
    // change DrawingAttributes according to the NormalPressure
    // Note that the change does not take effect until the next stroke
    if (NormalPressure != -1)
    {
        // display the pressure on a status label
        this.statusLabelPressure.Text = NormalPressure.ToString();
        e.Cursor.DrawingAttributes.Width = NormalPressure * 4;
        // if pressure is above 127, change color to Red
        if (NormalPressure > 127)
        {
            e.Cursor.DrawingAttributes.Color = Color.Red;
        }
        else
        {
            e.Cursor.DrawingAttributes.Color = mInkObject.DefaultDrawingAttributes.Color;
        }
    }
}

プラットフォーム

Windows Vista

.NET Framework および .NET Compact Framework では、各プラットフォームのすべてのバージョンはサポートしていません。サポートされているバージョンについては、「.NET Framework システム要件」を参照してください。

バージョン情報

.NET Framework

サポート対象 : 3.0

参照

参照

InkPicture クラス

InkPicture メンバ

Microsoft.Ink 名前空間

Cursor

InkCollectorNewPacketsEventArgs

InkPicture.DesiredPacketDescription

InkPicture.NewPackets