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