Compartilhar via


Stroke Event

Stroke Event

Occurs when the user draws a new stroke on any tablet.

Declaration

[C++]

void Stroke(
    [in] IInkCursor* Cursor,
    [in] IInkStrokeDisp* Stroke,
    [in, out] VARIANT_BOOL* Cancel
);

[Microsoft® Visual Basic® 6.0]

Public Event Stroke( _
    Cursor As IInkCursor, _
    Stroke As IInkStrokeDisp, _
    Cancel As Boolean _
)

Parameters

Cursor

[in] The IInkCursor object that generated the Stroke event.

Stroke

[in] The collected IInkStrokeDisp object.

Cancel

[in, out]. Specifies whether the event should be canceled. If true, the collection of the stroke is canceled.

Remarks

This event method is defined in the _IInkCollectorEvents, _IInkOverlayEvents, and _IInkPictureEvents dispatch-only interfaces (dispinterfaces) with an ID of DISPID_ICEStroke.

The Stroke event is fired when in select or erase mode, not just 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 is added to the InkStrokes collection. When the user first starts to draw a stroke, it is added immediately to the InkStrokes collection; however, the Stroke event does not fire until the stroke is complete. Therefore, strokes can exist in the InkStrokes collection that the Stroke event handler has not seen.

Example

[Visual Basic 6.0]

This Visual Basic 6.0 example demonstrates using the Stroke event handler of an InkCollector to store a custom property in each stroke that contains a timestamp, using the ExtendedProperties member. This sample application began with a simple form and added a command button and a list box, as well as a reference to the Microsoft Tablet PC Type Library. Each stroke drawn on the form stores a timestamp in its extended properties and, when the button is pressed, the list box is filled with a list of the timestamps of the strokes.

Option Explicit
Dim WithEvents theInkCollector As InkCollector
Dim theTimeGuid

Private Sub Command1_Click()
    Call PopulateList
End Sub

Private Sub Form_Load()
    'Add the InkCollector initialization.
    Set theInkCollector = New InkCollector
    theInkCollector.hWnd = Me.hWnd
    theInkCollector.Enabled = True
    ' This GUID constant will be used for the strokes'
    ' timestamp extended property.
    theTimeGuid = "{00000010-0011-0012-0010-000000000000}"
End Sub

Public Sub PopulateList()
    ' Clear the list before repopulating it.
    List1.Clear
    ' Query the InkCollector's Ink for its strokes collection.
    Dim theStrokes As InkStrokes
    Set theStrokes = theInkCollector.Ink.Strokes
    Dim theStroke As IInkStrokeDisp
    For Each theStroke In theStrokes
        ' If the timestamp property exists in this stroke:
        If _
        theStroke.ExtendedProperties.DoesPropertyExist(theTimeGuid) _
        Then
            Dim theTime As String
            ' Get the time data out of this stroke's extended
            ' properties list, using the previously defined
            ' Guid as a key to the required extended property.
            theTime = theStroke.ExtendedProperties(theTimeGuid).Data
            List1.AddItem (theTime)
        End If
    Next
End Sub

Private Sub theInkCollector_Stroke( _
ByVal Cursor As MSINKAUTLib.IInkCursor, _
ByVal Stroke As MSINKAUTLib.IInkStrokeDisp, _
Cancel As Boolean)
    Dim theExtendedProperty As IInkExtendedProperty
    ' Write the current time into each stroke when it is created
    ' using the Guid as a unique retrieval key.
    Set theExtendedProperty = Stroke.ExtendedProperties.Add(theTimeGuid, Now)
End Sub

Applies To