ExtendedProperties.Add Method
ExtendedProperties.Add Method |
Creates an ExtendedProperty object and adds it to the ExtendedProperties collection.
Definition
Visual Basic .NET Public Function Add( _
ByVal id As Guid, _
ByVal data As Object _
) As ExtendedPropertyC# public ExtendedProperty Add(
Guid id,
object data
);Managed C++ public: ExtendedProperty* Add(
Guid *id,
Object *data
);
Parameters
id System.Guid. The identifier of the new ExtendedProperty object. data System.Object. The data for the new ExtendedProperty object.
Return Value
Microsoft.Ink.ExtendedProperty. The new ExtendedProperty object.
Remarks
Note: You cannot store an empty ExtendedProperty object. The ExtendedProperty object must contain Data before it can be stored. If you add an ExtendedProperty object to a Stroke object to use at a later time, for example, an exception is thrown if the ExtendedProperty object contains no data.
You can pass in most value types and arrays of value types for the data parameter.
Note: If you call this method with the id parameter set to a globally unique identifier (GUID) that already exists in the ExtendedProperties collection, the new data replaces the existing data for the ExtendedProperty object with that GUID. To create additional ExtendedProperty objects, give them unique values for the id parameter.
Examples
[C#]
This C# example uses the InkCollector.Stroke event handler to store a timestamp on each Stroke object. During the event handler, the example adds the timestamp to the Stroke object's ExtendedProperties property. A Button control's Click event handler, theButton_Click, fills a ListBox control, theListBox, with a list of the timestamps.
//... 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 Stroke object's // timestamp extended property. 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 so an ExtendedProperty // can be recorded with each one. theInkCollector.Stroke += new InkCollectorStrokeEventHandler(TheStrokeHandler); } public void TheStrokeHandler(object sender, InkCollectorStrokeEventArgs e) { // Write the current time into this Stroke. // Get the timestamp as a long. long theTime = DateTime.Now.ToFileTime(); // Store the timestamp 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 property on this Stroke. if (theStroke.ExtendedProperties.DoesPropertyExist(theTimeGuid)) { // Get the raw data out of this Stroke's extended // properties list, by using the previously defined GUID. long theLong = (long)theStroke.ExtendedProperties[theTimeGuid].Data; // Turn the timestamp into a date-time string. string theTime = DateTime.FromFileTime(theLong).ToString(); // Add the string to the list box. theListBox.Items.Add(theTime); } } } // Event handler for the button's click event private void theButton_Click(object sender, System.EventArgs e) { //Calls the method to add timestamps to the list box. 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 InkCollector.Stroke event handler to store a timestamp on each Stroke object. During the event handler, the example adds the timestamp to the Stroke object's ExtendedProperties property. A Button control's Click event handler, theButton_Click, fills a ListBox control, theListBox, with a list of the timestamps.
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 object's ' timestamp extended property. 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 '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 so an ExtendedProperty 'can be recorded with each one. 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. ' Get the timestamp as a Long. Dim theTime As Long = DateTime.Now.ToFileTime() ' Store the timestamp under its own Guid 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 ' Test for the timestamp property on 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 extended ' properties list, by using the previously defined GUID. theLong = theStroke.ExtendedProperties(theTimeGuid).Data ' Turn the timestamp into a date-time string. theTime = DateTime.FromFileTime(theLong).ToString() ' Add the string to the list box. theListBox.Items.Add(theTime) End If Next End Sub ' Event handler for the button's click event Private Sub theButton_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles theButton.Click ' Calls the method to add timestamps to the list box. 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