InkPicture.DesiredPacketDescription 屬性
取得或設定與 InkPicture 物件上繪製之筆墨關聯的封包方面的所需資訊。
命名空間: Microsoft.Ink
組件: Microsoft.Ink (在 Microsoft.Ink.dll 中)
語法
'宣告
<BrowsableAttribute(False)> _
Public Property DesiredPacketDescription As Guid()
'用途
Dim instance As InkPicture
Dim value As Guid()
value = instance.DesiredPacketDescription
instance.DesiredPacketDescription = value
[BrowsableAttribute(false)]
public Guid[] DesiredPacketDescription { get; set; }
[BrowsableAttribute(false)]
public:
property array<Guid>^ DesiredPacketDescription {
array<Guid>^ get ();
void set (array<Guid>^ value);
}
/** @property */
/** @attribute BrowsableAttribute(false) */
public Guid[] get_DesiredPacketDescription()
/** @property */
/** @attribute BrowsableAttribute(false) */
public void set_DesiredPacketDescription(Guid[] value)
public function get DesiredPacketDescription () : Guid[]
public function set DesiredPacketDescription (value : Guid[])
屬性值
型別:array<System.Guid[]
Guid (英文) 物件的陣列,每個物件都表示與 InkPicture 物件上繪製之筆墨關聯的封包方面的資訊。
備註
封包描述是來自 PacketProperty 物件的 Guid (英文) 物件陣列。
DesiredPacketDescription 預設會包含來自 PacketProperty 物件的 X、Y 和 NormalPressure。如果將 DesiredPacketDescription 設定為其他項目,則也會加入 X 和 Y。例如,如果只將 DesiredPacketDescription 設定為 ButtonPressure,get 則會傳回 {X, Y, ButtonPressure},而非僅是 {ButtonPressure}。
當 DesiredPacketDescription 是設定為包含 PacketStatus 的項目時,PacketStatus 會被加到第三個位置。例如,如果將 DesiredPacketDescription 設定為 (a, b, c, d, PacketStatus, e, f),get 則會傳回 (X, Y, PacketStatus, a, b, c, d, e, f)。
在多重手寫板模式中,這是所有手寫板裝置的封包描述。如果有任何裝置不支援已知的封包描述屬性,則不會傳回屬性資料。
在將 InkEnabled 屬性從 false 變更為 true 之前,對這個屬性所做的變更並不會影響傳入的封包資料。
範例
下列範例為您示範如何使用 DesiredPacketDescription 屬性,表達對來自 PacketProperty 物件的 Guid (英文) 物件感興趣,然後在 NewPackets 期間使用公開的封包屬性。
首先,會初始化 DesiredPacketDescription 屬性並指派事件處理常式。
' Express interest in PacketStatus, TimerTick, and NormalPressure
' X and Y will be added automatically
Dim PacketDesc As Guid() = New Guid() _
{ _
PacketProperty.PacketStatus, _
PacketProperty.TimerTick, _
PacketProperty.NormalPressure _
}
' mInkObject can be InkCollector, InkOverlay, or InkPicture
mInkObject.DesiredPacketDescription = PacketDesc
' assign event handlers
AddHandler mInkObject.CursorInRange, New InkCollectorCursorInRangeEventHandler(AddressOf mInkObject_CursorInRange)
AddHandler mInkObject.NewPackets, New InkCollectorNewPacketsEventHandler(AddressOf mInkObject_NewPackets)
// Express interest in PacketStatus, TimerTick, and NormalPressure
// X and Y will be added automatically
Guid[] PacketDesc = new Guid[]
{
PacketProperty.PacketStatus,
PacketProperty.TimerTick,
PacketProperty.NormalPressure
};
// mInkObject can be InkCollector, InkOverlay, or InkPicture
mInkObject.DesiredPacketDescription = PacketDesc;
// assign event handlers
mInkObject.CursorInRange += new InkCollectorCursorInRangeEventHandler(mInkObject_CursorInRange);
mInkObject.NewPackets += new InkCollectorNewPacketsEventHandler(mInkObject_NewPackets);
當 CursorInRange 事件引發時,會檢查 InkPicture 物件是否為第一次與這個特定 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