다음을 통해 공유


InkOverlay.NewPackets 이벤트

업데이트: 2007년 11월

InkOverlay가 패킷을 받으면 발생합니다.

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

구문

‘선언
Public Event NewPackets As InkCollectorNewPacketsEventHandler
‘사용 방법
Dim instance As InkOverlay
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에서는 이벤트를 지원하지 않습니다.

설명

InkOverlay 개체는 스트로크를 수집하는 동안 패킷을 받습니다. 패킷 이벤트는 빠르게 발생하므로 NewPackets 이벤트 처리기가 고속으로 이벤트를 처리할 수 있어야 성능이 저하되지 않습니다.

이벤트 처리기는 이 이벤트에 대한 데이터가 들어 있는 InkCollectorNewPacketsEventArgs 형식의 인수를 받습니다.

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

이벤트 처리기에서 너무 많은 코드가 실행되면 이 이벤트로 인해 잉크 성능이 저하될 수 있습니다.

예제

이 예제에서는 CursorInRange 이벤트 및 NewPackets 이벤트에 대한 알림을 신청하여 DrawingAttributes 개체를 조작하기 위한 잉크 압력 데이터를 가져오고 해당 정보를 사용하는 방법을 보여 줍니다.

CursorInRange 이벤트가 발생하면 InkCollector 개체가 해당 Cursor 개체와 처음으로 접촉했는지 확인합니다. 확인에 성공하면 DrawingAttributes 속성에 DefaultDrawingAttributes 속성의 복제본이 할당됩니다. 이렇게 하면 이후에 DrawingAttributes 속성에 액세스할 때 null 참조 예외가 throw되지 않습니다.

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에서 지원

참고 항목

참조

InkOverlay 클래스

InkOverlay 멤버

Microsoft.Ink 네임스페이스

Cursor

InkCollectorNewPacketsEventArgs

InkOverlay.DesiredPacketDescription

InkOverlay.NewPackets