ExtendedProperties.Add 方法

创建一个 ExtendedProperty 对象,然后将它添加到 ExtendedProperties 集合中。

命名空间:  Microsoft.Ink
程序集:  Microsoft.Ink(在 Microsoft.Ink.dll 中)

语法

声明
Public Function Add ( _
    id As Guid, _
    data As Object _
) As ExtendedProperty
用法
Dim instance As ExtendedProperties
Dim id As Guid
Dim data As Object
Dim returnValue As ExtendedProperty

returnValue = instance.Add(id, data)
public ExtendedProperty Add(
    Guid id,
    Object data
)
public:
ExtendedProperty^ Add(
    Guid id, 
    Object^ data
)
public ExtendedProperty Add(
    Guid id,
    Object data
)
public function Add(
    id : Guid, 
    data : Object
) : ExtendedProperty

参数

返回值

类型:Microsoft.Ink.ExtendedProperty
新的 ExtendedProperty 对象。

备注

备注

不能存储空的 ExtendedProperty 对象。ExtendedProperty 对象必须包含 Data 才能进行存储。例如,如果 ExtendedProperty 对象不包含任何数据,而您将该 ExtendedProperty 对象添加到 Stroke 对象供以后使用,则将引发异常。

备注

如果调用此方法时将 ID 参数设置为 ExtendedProperties 集合中已经存在的全局唯一标识符 (GUID),则新数据将替换具有该 GUID 的 ExtendedProperty 对象的现有数据。若要另外创建 ExtendedProperty 对象,请为 id 参数提供唯一值。

示例

此示例演示如何订阅 CursorDown 事件和 Stroke 事件来计算用户创建笔画所用的时间长度。

在笔画开始时,会激发 CursorDown 事件。当前时间会放置在 Stroke 对象的 ExtendedProperties 集合中。

Private Sub mInkObject_CursorDown(ByVal sender As Object, ByVal e As InkCollectorCursorDownEventArgs)
    ' add extended property indicating the time the stroke started
    ' STROKE_START_GUID is class level string via GUID generator
    e.Stroke.ExtendedProperties.Add(New Guid(STROKE_START_GUID), DateTime.Now)
End Sub
private void mInkObject_CursorDown(object sender, InkCollectorCursorDownEventArgs e)
{
    // add extended property indicating the time the stroke started
    // STROKE_START_GUID is class level string via GUID generator
    e.Stroke.ExtendedProperties.Add(new Guid(STROKE_START_GUID), DateTime.Now);
}

笔画完成时,会激发 Stroke 事件。起始时间是从 Stroke 对象的 ExtendedProperties 集合中获取的,可用于计算所用的时间。

Private Sub mInkObject_Stroke1(ByVal sender As Object, ByVal e As InkCollectorStrokeEventArgs)
    ' check to see if extended property for start time exists
    ' Attempting to access an extended property that hasn't been created throws an exception
    ' STROKE_START_GUID is class level string via GUID generator
    If (e.Stroke.ExtendedProperties.DoesPropertyExist(New Guid(STROKE_START_GUID))) Then

        Dim startTime As DateTime = DirectCast(e.Stroke.ExtendedProperties(New Guid(STROKE_START_GUID)).Data, DateTime)
        Dim endTime As DateTime = DateTime.Now
        Dim span As TimeSpan = New TimeSpan(endTime.Ticks - startTime.Ticks)

        ' add extended property indicating the time the stroke ended
        ' STROKE_END_GUID is class level string via GUID generator
        e.Stroke.ExtendedProperties.Add(New Guid(STROKE_END_GUID), endTime)

        ' display the number of seconds in creating this stroke
        Me.statusLabelStrokeTime.Text = span.TotalSeconds.ToString()
    End If
End Sub
private void mInkObject_Stroke1(object sender, InkCollectorStrokeEventArgs e)
{
    // check to see if extended property for start time exists
    // Attempting to access an extended property that hasn't been created throws an exception
    // STROKE_START_GUID is class level string via GUID generator
    if (e.Stroke.ExtendedProperties.DoesPropertyExist(new Guid(STROKE_START_GUID)))
    {
        DateTime startTime = (DateTime)e.Stroke.ExtendedProperties[new Guid(STROKE_START_GUID)].Data;
        DateTime endTime = DateTime.Now;
        TimeSpan span = new TimeSpan(endTime.Ticks - startTime.Ticks);

        // add extended property indicating the time the stroke ended
        // STROKE_END_GUID is class level string via GUID generator
        e.Stroke.ExtendedProperties.Add(new Guid(STROKE_END_GUID), endTime);

        // display the number of seconds in creating this stroke
        this.statusLabelStrokeTime.Text = span.TotalSeconds.ToString();
    }
}

平台

Windows Vista

.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求

版本信息

.NET Framework

受以下版本支持:3.0

另请参见

参考

ExtendedProperties 类

ExtendedProperties 成员

Microsoft.Ink 命名空间

ExtendedProperty

Strokes