共用方式為


Ink.CreateStroke 方法 (array<Int32[], TabletPropertyDescriptionCollection)

從封包資料建立 Stroke 物件。

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

語法

'宣告
Public Function CreateStroke ( _
    packetData As Integer(), _
    tabletPropertyDescriptionCollection As TabletPropertyDescriptionCollection _
) As Stroke
'用途
Dim instance As Ink
Dim packetData As Integer()
Dim tabletPropertyDescriptionCollection As TabletPropertyDescriptionCollection
Dim returnValue As Stroke

returnValue = instance.CreateStroke(packetData, _
    tabletPropertyDescriptionCollection)
public Stroke CreateStroke(
    int[] packetData,
    TabletPropertyDescriptionCollection tabletPropertyDescriptionCollection
)
public:
Stroke^ CreateStroke(
    array<int>^ packetData, 
    TabletPropertyDescriptionCollection^ tabletPropertyDescriptionCollection
)
public Stroke CreateStroke(
    int[] packetData,
    TabletPropertyDescriptionCollection tabletPropertyDescriptionCollection
)
public function CreateStroke(
    packetData : int[], 
    tabletPropertyDescriptionCollection : TabletPropertyDescriptionCollection
) : Stroke

參數

  • packetData
    型別:array<System.Int32[]
    用於組成 Stroke 物件的封包資料陣列。

傳回值

型別:Microsoft.Ink.Stroke
新建立的筆劃。
新建立的 Stroke 物件。

備註

packetData 參數中的陣列大小,必須能夠由 tabletPropertyDescriptionCollection 參數的大小整除。

ms569571.alert_note(zh-tw,VS.90).gif注意事項:

packetData 參數中每個封包的前兩個元素必須是 X 再來是 Y。如果沒有在每個封包的第一個和第二個位置分別指定 X 和 Y,就會擲回 ArgumentException

範例

在這個範例中,表示不規則正弦波的筆劃是從隨機封包資料建立的。首先會取得 PacketPropertyXYTabletPropertyMetrics,才能使用這些 PacketProperty 型別的 TabletPropertyDescription 物件初始化 TabletPropertyDescriptionCollection。如果預設手寫板支援 NormalPressure,則這個項目也會加入集合中。接下來會建立實際的封包資料,並傳遞給 CreateStroke 方法。

Dim allTablets As Tablets = New Tablets()
' get the property metrics for X and Y
Dim MetricX As TabletPropertyMetrics = allTablets.DefaultTablet.GetPropertyMetrics(PacketProperty.X)
Dim MetricY As TabletPropertyMetrics = allTablets.DefaultTablet.GetPropertyMetrics(PacketProperty.Y)
' create the TabletPropertyDescriptionCollection, add X and Y
Dim tpDescCollection As TabletPropertyDescriptionCollection = New TabletPropertyDescriptionCollection()
tpDescCollection.Add(New TabletPropertyDescription(PacketProperty.X, MetricX))
tpDescCollection.Add(New TabletPropertyDescription(PacketProperty.Y, MetricY))

' see if the default tablet supports pressure
Dim supportPressure As Boolean = allTablets.DefaultTablet.IsPacketPropertySupported(PacketProperty.NormalPressure)
' if so, add NormalPressure to TabletPropertyDescriptionCollection
If supportPressure Then
    Dim MetricP As TabletPropertyMetrics = allTablets.DefaultTablet.GetPropertyMetrics(PacketProperty.NormalPressure)
    tpDescCollection.Add(New TabletPropertyDescription(PacketProperty.NormalPressure, MetricP))
End If
' init random number generator
Dim R As Random = New Random()
' init total PacketCount, slotPerPacket and packet data array
Const PACKET_COUNT As Integer = 250
Dim slotPerPacket As Integer = tpDescCollection.Count
Dim pData((PACKET_COUNT * slotPerPacket) - 1) As Integer
' assign packet values
For k As Integer = 0 To PACKET_COUNT - 1
    ' assign X - X will increment by 106
    pData(k * slotPerPacket) = (k * 106)
    ' assign Y - Y will be 6000 +- 1500
    pData((k * slotPerPacket) + 1) = 6000 + R.Next(-1500, 1500)
    ' assign Pressure if supported, 25-255
    If (supportPressure) Then
        pData((k * slotPerPacket) + 2) = R.Next(25, 255)
    End If
    next
' create the Stroke
mInkOverlay.Ink.CreateStroke(pData, tpDescCollection)
mInkOverlay.AttachedControl.Invalidate()
Tablets allTablets = new Tablets();
// get the property metrics for X and Y
TabletPropertyMetrics MetricX = allTablets.DefaultTablet.GetPropertyMetrics(PacketProperty.X);
TabletPropertyMetrics MetricY = allTablets.DefaultTablet.GetPropertyMetrics(PacketProperty.Y);
// create the TabletPropertyDescriptionCollection, add X and Y
TabletPropertyDescriptionCollection tpDescCollection = new TabletPropertyDescriptionCollection();
tpDescCollection.Add(new TabletPropertyDescription(PacketProperty.X, MetricX));
tpDescCollection.Add(new TabletPropertyDescription(PacketProperty.Y, MetricY));

// see if the default tablet supports pressure
bool supportPressure = allTablets.DefaultTablet.IsPacketPropertySupported(PacketProperty.NormalPressure);
// if so, add NormalPressure to TabletPropertyDescriptionCollection
if (supportPressure)
{
    TabletPropertyMetrics MetricP = allTablets.DefaultTablet.GetPropertyMetrics(PacketProperty.NormalPressure);
    tpDescCollection.Add(new TabletPropertyDescription(PacketProperty.NormalPressure, MetricP));
}
// init random number generator
Random R = new Random();
// init total PacketCount, slotPerPacket and packet data array
const int PACKET_COUNT = 250;
int slotPerPacket = tpDescCollection.Count;
int[] pData = new int[PACKET_COUNT*slotPerPacket];
// assign packet values
for (int k = 0; k < PACKET_COUNT; k++)
{
    // assign X - X will increment by 106
    pData[k * slotPerPacket] = (k * 106);
    // assign Y - Y will be 6000 +- 1500
    pData[(k * slotPerPacket) + 1] = 6000 + R.Next(-1500, 1500);
    // assign Pressure if supported, 25-255
    if (supportPressure)
    {
        pData[(k * slotPerPacket) + 2] = R.Next(25, 255);
    }
}
// create the Stroke
mInkOverlay.Ink.CreateStroke(pData, tpDescCollection);
mInkOverlay.AttachedControl.Invalidate();

平台

Windows Vista

.NET Framework 和 .NET Compact Framework 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱 .NET Framework 系統需求

版本資訊

.NET Framework

支援版本:3.0

請參閱

參考

Ink 類別

Ink 成員

CreateStroke 多載

Microsoft.Ink 命名空間

Stroke

TabletPropertyDescriptionCollection.InkToDeviceScaleX

TabletPropertyDescriptionCollection.InkToDeviceScaleY

Ink.CreateStrokes

Ink.DeleteStroke

Ink.DeleteStrokes