Share via


InkPicture.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 InkPicture 
Dim handler As InkCollectorStrokeEventHandler 

AddHandler instance.Stroke, handler
public event InkCollectorStrokeEventHandler Stroke
public:
 event InkCollectorStrokeEventHandler^ Stroke {
    void add (InkCollectorStrokeEventHandler^ value);
    void remove (InkCollectorStrokeEventHandler^ value);
}
JScript does not support events.

Remarks

The event handler receives an argument of type InkCollectorStrokeEventArgs that contains 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, Stroke objects can exist in the Strokes collection before the Stroke event handler fires for that Stroke object.

Examples

This example demonstrates how you can subscribe to the CursorDown event, and the Stroke event to calculate the length of time it takes the user to create a stroke.

At the beginning of a stroke, the CursorDown event fires. The current time is placed into the ExtendedProperties collection of the Stroke object.

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);
}

When the stroke is complete, the Stroke event fires. The start time is retrieved from the ExtendedProperties collection of the Stroke object, and used to calculate the elapsed time.

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();
    }
}

In this example, the event handler for the Stroke event creates a shadow stroke by creating a new Stroke object based upon the current Stroke object, and then changing the color and position of the newly created Stroke object.

Private Sub mInkObject_Stroke2(ByVal sender As Object, ByVal e As InkCollectorStrokeEventArgs)
    Me.mNumStroke = Me.mNumStroke + 1
    statusLabelStrokeCount.Text = Me.mNumStroke.ToString()

    ' Add a new stroke created from the stroke points of the current stroke 
    Dim StrokeShadow As Stroke = e.Stroke.Ink.CreateStroke(e.Stroke.GetPoints())

    ' clone the DrawingAttributes and set color to Gray
    StrokeShadow.DrawingAttributes = e.Stroke.DrawingAttributes.Clone()
    StrokeShadow.DrawingAttributes.Color = Color.Gray

    ' use MaskPen to keep the shadow stroke in the background
    StrokeShadow.DrawingAttributes.RasterOperation = RasterOperation.MaskPen

    ' offset the shadow stroke
    StrokeShadow.Move(200, 200)

    ' redraw the ink canvas
    panelInkCanvas.Invalidate()

End Sub
private void mInkObject_Stroke2(object sender, InkCollectorStrokeEventArgs e)
{
    this.mNumStroke++;
    statusLabelStrokeCount.Text = this.mNumStroke.ToString();

    // Add a new stroke created from the stroke points of the current stroke
    Stroke StrokeShadow = e.Stroke.Ink.CreateStroke(e.Stroke.GetPoints());

    // clone the DrawingAttributes and set color to Gray
    StrokeShadow.DrawingAttributes = e.Stroke.DrawingAttributes.Clone();
    StrokeShadow.DrawingAttributes.Color = Color.Gray;

    // use MaskPen to keep the shadow stroke in the background
    StrokeShadow.DrawingAttributes.RasterOperation = RasterOperation.MaskPen;

    // offset the shadow stroke
    StrokeShadow.Move(200, 200);

    // redraw the ink canvas
    panelInkCanvas.Invalidate();

}

Platforms

Windows 7, Windows Vista, Windows Server 2008 R2, Windows Server 2008

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Version Information

.NET Framework

Supported in: 3.0

See Also

Reference

InkPicture Class

InkPicture Members

Microsoft.Ink Namespace

Cursor

InkCollectorStrokeEventArgs

Stroke

Strokes.StrokesAdded