InkOverlay.Stroke Event
Occurs when the user finishes drawing a new stroke on any tablet.
Namespace: Microsoft.Ink
Assembly: Microsoft.Ink (in microsoft.ink.dll)
Syntax
'Declaration
Public Event Stroke As InkCollectorStrokeEventHandler
'Usage
Dim instance As InkOverlay
Dim handler As InkCollectorStrokeEventHandler
AddHandler instance.Stroke, handler
public event InkCollectorStrokeEventHandler Stroke
public:
event InkCollectorStrokeEventHandler^ Stroke {
void add (InkCollectorStrokeEventHandler^ value);
void remove (InkCollectorStrokeEventHandler^ value);
}
/** @event */
public void add_Stroke (InkCollectorStrokeEventHandler value)
/** @event */
public void remove_Stroke (InkCollectorStrokeEventHandler value)
In JScript, you can handle the events defined by a class, but you cannot define your own.
Not applicable.
Remarks
The event handler receives an argument of type InkCollectorStrokeEventArgs containing data about this event.
When you create an InkCollectorStrokeEventHandler delegate, you identify the method that handles the event. To associate the event with your event handler, add an instance of the delegate to the event. The event handler is called whenever the event occurs, unless you remove the delegate. The default event interest is on.
The Stroke event fires when in select or erase mode, not only when inserting ink. This requires that you monitor the editing mode (which you are responsible for setting) and be aware of the mode before interpreting the event. The advantage of this requirement is greater freedom to innovate on the platform through greater awareness of platform events.
Note
The Stroke event fires when the user finishes drawing a stroke, not when a Stroke object is added to the Strokes collection. When the user first starts to draw a stroke, it is added immediately to the Strokes collection; however, the Stroke event does not fire until the stroke is complete. Therefore, a Stroke object may exist in the Strokes collection before the Stroke event handler fires for that Stroke object.
Example
This C# example uses the InkOverlay.Stroke event handler to store a time stamp on each Stroke object. During the event handler, the example adds the time stamp to the Stroke object's ExtendedProperties property. A Button control's Click event handler, theButton_Click
, fills a ListBoxListBox control, theListBox
, with a list of the time stamps.
//...
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.
InkOverlay theInkOverlay;
// This GUID constant will be used for the strokes'
// 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 InkOverlay with the form's
// window handle, then enable it.
theInkOverlay = new InkOverlay(Handle);
theInkOverlay.Enabled = true;
// Add a handler for Stroke Events so we can record
// an extended property with each one.
theInkOverlay.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 the Guid key.
e.Stroke.ExtendedProperties.Add(theTimeGuid, theTime);
}
private void PopulateList()
{
//Clear the list before repopulating it.
theListBox.Items.Clear();
// Query the InkOverlay's Ink for its strokes collection.
Strokes theStrokes = theInkOverlay.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, using the previously defined
// Guid as a key to the wanted extended property.
long theLong = (long)theStroke.ExtendedProperties[theTimeGuid].Data;
// Then turn it (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)
{
theInkOverlay.Dispose();
theInkOverlay = null;
}
}
}
This Microsoft Visual Basic .NET example uses the InkOverlay.Stroke event handler to store a time stamp on each Stroke object. During the event handler, the example adds the time stamp to the Stroke object's ExtendedProperties property. A Button control's Click event handler, theButton_Click
, fills a ListBoxListBox control, theListBox
, with a list of the time stamps.
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 theInkOverlay As InkOverlay
' This GUID constant will be used for the strokes'
' 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
'Add the InkOverlay initialization and Stroke event handler.
theInkOverlay = New InkOverlay(Handle)
theInkOverlay.Enabled = True
AddHandler theInkOverlay.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 the 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 InkOverlay's Ink for its strokes collection.
Dim theStrokes As Strokes = theInkOverlay.Ink.Strokes
Dim theStroke As Stroke
For Each theStroke In theStrokes
' If the timestamp property 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 extended
' properties list, using the previously defined
' Guid as a key to the extended property we want.
theLong = theStroke.ExtendedProperties(theTimeGuid).Data
' Then turn that Long (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
theInkOverlay.Dispose()
Set theInkOverlay = Nothing
End Sub
End Class
Platforms
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.
Version Information
.NET Framework
Supported in: 3.0
See Also
Reference
InkOverlay Class
InkOverlay Members
Microsoft.Ink Namespace
Cursor
InkCollectorStrokeEventArgs
Stroke
Strokes.StrokesAdded