ExtendedProperties.DoesPropertyExist Method

ExtendedProperties.DoesPropertyExist Method

Indicates whether a specified ExtendedProperty object exists in the ExtendedProperties collection.

Definition

Visual Basic .NET Public Function DoesPropertyExist( _
ByVal id As Guid _
) As Boolean
C# public bool DoesPropertyExist(
Guid id
);
Managed C++ public: bool* DoesPropertyExist(
Guid *id
);

Parameters

id System.Guid. The globally unique identifier (GUID) of the property to check for.

Return Value

System.Boolean. Whether the specified ExtendedProperty object exists in the ExtendedProperties collection.

true The specified ExtendedProperty object exists in the ExtendedProperties collection.
false The specified ExtendedProperty object does not exist in the ExtendedProperties collection.

Examples

[C#]

This C# example uses the Stroke event handler to store an ExtendedProperty in each Stroke object. The ExtendedProperty object contains a timestamp, which is added to the Stroke by using the Stroke object's ExtendedProperties property. This sample started with a generated C# application and added a button, theButton, and a list box, theListBox, to the main form. When the button is pressed, the list box is populated with a list of the timestamps of the Stroke objects.

//...
using Microsoft.Ink;

namespace CS_StrokeEvent
{
    public class Form1 : System.Windows.Forms.Form
    {
        private System.Windows.Forms.ListBox theListBox;
        private System.Windows.Forms.Button theButton;

        //...

        // Add the following after Main() in the generated code.

        InkCollector theInkCollector;
        // This GUID constant is used for the Strokes'
        // timestamp ExtendedProperty.
        Guid theTimeGuid = new Guid(10, 11, 12, 10, 0, 0, 0, 0, 0, 0, 0);

        private void Form1_Load(object sender, System.EventArgs e)
        {
            // Initialize the InkCollector with the form's
            // window handle, then enable it.
            theInkCollector = new InkCollector(Handle);
            theInkCollector.Enabled = true;
            // Add a handler for Stroke Events to record
            // an ExtendedProperty with each one.
            theInkCollector.Stroke += new InkCollectorStrokeEventHandler(TheStrokeHandler);
        }

        public void TheStrokeHandler(object sender, InkCollectorStrokeEventArgs e)
        {
            // Write the current time into this Stroke.
            // First get the time as a long.
            long theTime = DateTime.Now.ToFileTime();
            // Store the data under its own Guid key.
            e.Stroke.ExtendedProperties.Add(theTimeGuid, theTime);
        }

        private void PopulateList()
        {
            //Clear the list before repopulating it.
            theListBox.Items.Clear();
            // Query the InkCollector's Ink for its Strokes collection.
            Strokes theStrokes = theInkCollector.Ink.Strokes;
            foreach (Stroke theStroke in theStrokes)
            {
                // Test for the timestamp ExtendedProperty on this Stroke.
                if (theStroke.ExtendedProperties.DoesPropertyExist(theTimeGuid))
                {
                    // Get the raw data out of this Stroke's ExtendedProperties
                    // list by using the previously defined Guid.
                    long theLong = (long)theStroke.ExtendedProperties[theTimeGuid].Data;
                    // Then turn the timestamp (as a FileTime) into a time string.
                    string theTime = DateTime.FromFileTime(theLong).ToString();
                    // Add the string to the listbox.
                    theListBox.Items.Add(theTime);
                }
            }
        }

        private void theButton_Click(object sender, System.EventArgs e)
        {
            PopulateList();
        }

        // Event handler for the form's closed event
        private void Form1_Closed(object sender, System.EventArgs e)
        {
            theInkCollector.Dispose();
            theInkCollector = null;
        }
    }
}
                

[VB.NET]

This Microsoft® Visual Basic® .NET example uses the Stroke event handler to store an ExtendedProperty in each Stroke object. The ExtendedProperty object contains a timestamp, which is added to the Stroke by using the Stroke object's ExtendedProperties property. This sample started with a generated Visual Basic .NET application and added a button, theButton, and a list box, theListBox, to the main form. When the button is pressed, the list box is populated with a list of the timestamps of the Stroke objects.

Imports Microsoft.Ink
Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
'... This section is generated automatically.
#End Region

    Private theInkCollector As InkCollector
    ' This GUID constant is used for the Strokes'
    ' timestamp ExtendedProperty.
    Public theTimeGuid As Guid = _
        New Guid(10, 11, 12, 10, 0, 0, 0, 0, 0, 0, 0)

    Private Sub Form1_Load(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles MyBase.Load
        'Add the InkCollector initialization and Stroke event handler.
        theInkCollector = New InkCollector(Handle)
        theInkCollector.Enabled = True
        AddHandler theInkCollector.Stroke, AddressOf TheStrokeHandler
    End Sub

    Public Sub TheStrokeHandler( _
    ByVal sender As Object, _
    ByVal e As InkCollectorStrokeEventArgs)
        ' Write the current time into this Stroke.
        ' First, get the current time as a Long FileTime.
        Dim theTime As Long = DateTime.Now.ToFileTime()
        ' Then store this value using its own Guid
        ' as a unique retrieval key.
        e.Stroke.ExtendedProperties.Add(theTimeGuid, theTime)
    End Sub

    Public Sub PopulateList()
        ' Clear the list before repopulating it.
        theListBox.Items.Clear()
        ' Query the InkCollector's Ink for its Strokes collection.
        Dim theStrokes As Strokes = theInkCollector.Ink.Strokes
        Dim theStroke As Stroke
        For Each theStroke In theStrokes
            ' If the timestamp ExtendedProperty exists in this Stroke:
            If _
            theStroke.ExtendedProperties.DoesPropertyExist(theTimeGuid) _
            Then
                Dim theLong As Long
                Dim theTime As String
                ' Get the raw data out of this Stroke's ExtendedProperties
                ' list by using the previously defined Guid.
                theLong = theStroke.ExtendedProperties(theTimeGuid).Data
                ' Then turn the timestamp (as a FileTime) into a string.
                theTime = DateTime.FromFileTime(theLong).ToString()
                theListBox.Items.Add(theTime)
            End If
        Next
    End Sub

    Private Sub theButton_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles theButton.Click
        PopulateList()
    End Sub

    'Event handler for the form's closed event
    Private Sub Form1_Closed(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Closed
        theInkCollector.Dispose()
        Set theInkCollector = Nothing
    End Sub
End Class
                

See Also