InkCollector.Stroke 事件

当用户在任何 Tablet 上绘制完一个新笔画 时发生。

命名空间:  Microsoft.Ink
程序集:  Microsoft.Ink(在 Microsoft.Ink.dll 中)

语法

声明
Public Event Stroke As InkCollectorStrokeEventHandler
用法
Dim instance As InkCollector
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)
JScript 不支持事件。

备注

事件处理程序接收 InkCollectorStrokeEventArgs 类型的参数,该参数包含有关此事件的数据。

创建 InkCollectorStrokeEventHandler 委托时,需要标识将处理该事件的方法。若要将该事件与事件处理程序关联,请将该委托的一个实例添加到事件中。除非移除了该委托,否则每当发生该事件时就会调用此事件处理程序。默认事件关注处于打开状态。

不仅在插入墨迹时,在选择或擦除模式下,也会激发 Stroke 事件。这就要求您监视编辑模式(您负责设置)并在解释事件之前注意模式。这一要求的好处在于通过注意平台事件在平台上获得更大的创新自由。

备注

当用户绘制完一个笔画时,而不是将笔画添加到 Strokes 集合中时,将激发 Stroke 事件。当用户首次开始绘制某个笔画时,该笔画会立即添加到 Strokes 集合中;但是,只有在该笔画完成时,才会激发 Stroke 事件。因此,在激发 Stroke 对象的 Stroke 事件处理程序之前,该 Stroke 对象可能已存在于 Strokes 集合中。

示例

此示例演示如何订阅 CursorDown 事件和 Stroke 事件来计算用户创建笔画所用的时间长度。

在笔画开始时,会激发 CursorDown 事件。当前时间会放置在 Stroke 对象的 ExtendedProperties 集合中。

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

笔画完成时,会激发 Stroke 事件。起始时间是从 Stroke 对象的 ExtendedProperties 集合中获取的,可用于计算所用的时间。

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

在此示例中,Stroke 事件的事件处理程序创建阴影笔画的方法如下:根据当前 Stroke 对象创建新的 Stroke 对象,然后更改新创建的 Stroke 对象的颜色和位置。

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

}

平台

Windows Vista

.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求

版本信息

.NET Framework

受以下版本支持:3.0

另请参见

参考

InkCollector 类

InkCollector 成员

Microsoft.Ink 命名空间

InkCollectorStrokeEventArgs

Cursor

Stroke

Strokes.StrokesAdded