InkCollector.NewPackets 事件
會在 InkCollector 物件接收封包時發生。
命名空間: Microsoft.Ink
組件: Microsoft.Ink (在 Microsoft.Ink.dll 中)
語法
'宣告
Public Event NewPackets As InkCollectorNewPacketsEventHandler
'用途
Dim instance As InkCollector
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 不支援事件。
備註
InkCollector 物件正在收集筆劃的同時也會接收封包。封包事件的發生速度很快,因此 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
請參閱
參考
InkCollectorNewPacketsEventArgs
InkCollector.NewPackets