共用方式為


InkCollectorNewPacketsEventHandler 委派

表示處理 InkCollector 物件之 NewPackets 事件的方法。

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

語法

'宣告
Public Delegate Sub InkCollectorNewPacketsEventHandler ( _
    sender As Object, _
    e As InkCollectorNewPacketsEventArgs _
)
'用途
Dim instance As New InkCollectorNewPacketsEventHandler(AddressOf HandlerMethod)
public delegate void InkCollectorNewPacketsEventHandler(
    Object sender,
    InkCollectorNewPacketsEventArgs e
)
public delegate void InkCollectorNewPacketsEventHandler(
    Object^ sender, 
    InkCollectorNewPacketsEventArgs^ e
)
/** @delegate */
public delegate void InkCollectorNewPacketsEventHandler(
    Object sender,
    InkCollectorNewPacketsEventArgs e
)
JScript 不支援委派。

參數

備註

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

正在收集筆劃的同時也會接收封包。封包事件的發生速度很快,因此 NewPackets 事件處理常式必須很快進行處理,否則筆墨效能會受到影響。

範例

這個範例會示範如何訂閱 CursorInRange 事件,還有 NewPackets 事件如何取得筆壓資料,然後使用該資訊來管理 DrawingAttributes 物件。

CursorInRange 事件引發時,會檢查 InkCollector 物件是否第一次接觸這個特定 Cursor 物件。如果是,則會將 DefaultDrawingAttributes 屬性的複製品 (Clone) 指派給 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

請參閱

參考

Microsoft.Ink 命名空間

Cursor

InkCollectorNewInAirPacketsEventHandler

Stroke