共用方式為


InkEdit.Stroke 事件

發生於使用者在任何手寫板上完成繪製新「筆劃」時。

命名空間:  Microsoft.Ink
組件:  Microsoft.Ink (在 Microsoft.Ink.dll 中)

語法

'宣告
Public Event Stroke As InkEditStrokeEventHandler
'用途
Dim instance As InkEdit
Dim handler As InkEditStrokeEventHandler

AddHandler instance.Stroke, handler
public event InkEditStrokeEventHandler Stroke
public:
 event InkEditStrokeEventHandler^ Stroke {
    void add (InkEditStrokeEventHandler^ value);
    void remove (InkEditStrokeEventHandler^ value);
}
/** @event */
public void add_Stroke (InkEditStrokeEventHandler value)
/** @event */
public void remove_Stroke (InkEditStrokeEventHandler value)
JScript 不支援事件。

備註

事件處理常式會收到 InkCollectorStrokeEventArgs 型別的引數,其中包含這個事件的相關資料。

在建立 InkCollectorStrokeEventHandler 委派時,您會識別處理事件的方法。若要使事件與您的事件處理常式產生關聯,請將委派的執行個體加入至事件。除非您移除委派,否則每當事件發生時就會呼叫事件處理常式。相關事件的預設是開啟。

範例

這個範例示範如何訂閱 Gesture 事件及 Stroke 事件,以便擴充 ApplicationGesture 的功能。

Gesture 事件引發時,會檢查筆勢和 InkEdit 控制項的目前狀態。必要時,會修改筆勢的行為並取消事件。

Private Sub mInkEdit_Gesture(ByVal sender As Object, ByVal e As InkEditGestureEventArgs)
    ' There might be more than one gesture passed in InkEditGestureEventArgs
    ' The gestures are arranged in order of confidence from most to least
    ' This event handler is only concerned with the first (most confident) gesture
    ' and only if the gesture is ApplicationGesture.Left with strong confidence
    Dim G As Gesture = e.Gestures(0)
    If (ApplicationGesture.Left = G.Id And RecognitionConfidence.Strong = G.Confidence) Then
        Dim pInkEdit As InkEdit = DirectCast(sender, InkEdit)
        ' by default, ApplicationGesture.Left maps to Backspace
        ' If the insertion point is at the beginning of the text
        ' and there is no text selected, then Backspace does not do anything.
        ' In this case, we will alter the gesture to map to Delete instead
        If (0 = pInkEdit.SelectionStart And 0 = pInkEdit.SelectionLength And pInkEdit.Text.Length > 0) Then
            ' take out the first character of the string
            pInkEdit.Text = pInkEdit.Text.Remove(0, 1)
            ' save the stroke ID in a class level var for use in the Stroke event
            Me.mStrokeID = e.Strokes(0).Id
            ' cancel the gesture so it won't perform the default action
            e.Cancel = True
        End If
    End If
End Sub
private void mInkEdit_Gesture(object sender, InkEditGestureEventArgs e)
{
    // There might be more than one gesture passed in InkEditGestureEventArgs
    // The gestures are arranged in order of confidence from most to least
    // This event handler is only concerned with the first (most confident) gesture
    // and only if the gesture is ApplicationGesture.Left with strong confidence
    Gesture G = e.Gestures[0];
    if (ApplicationGesture.Left == G.Id &&  RecognitionConfidence.Strong == G.Confidence)
    {
        InkEdit pInkEdit = (InkEdit)sender;

        // by default, ApplicationGesture.Left maps to Backspace
        // If the insertion point is at the beginning of the text
        // and there is no text selected, then Backspace does not do anything.
        // In this case, we will alter the gesture to map to Delete instead
        if (0 == pInkEdit.SelectionStart && 0 == pInkEdit.SelectionLength && pInkEdit.Text.Length > 0)
        {
            // take out the first character of the string
            pInkEdit.Text = pInkEdit.Text.Remove(0, 1);
            // save the stroke ID in a class level var for use in the Stroke event
            this.mStrokeID = e.Strokes[0].Id;
            // cancel the gesture so it won't perform the default action
            e.Cancel = true;
        }
    }
}

當 Stroke 事件引發時,如果筆劃是用來產生筆勢的筆劃,但是筆勢的行為已在 Gesture 事件中修改過,則會取消這個事件。這會使筆劃無法呈現。

Private Sub mInkEdit_Stroke(ByVal sender As Object, ByVal e As InkEditStrokeEventArgs)
    e.Cancel = (e.Stroke.Id = Me.mStrokeID)
End Sub
private void mInkEdit_Stroke(object sender, InkEditStrokeEventArgs e)
{
    e.Cancel = (e.Stroke.Id == this.mStrokeID);
}

平台

Windows Vista

.NET Framework 和 .NET Compact Framework 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱 .NET Framework 系統需求

版本資訊

.NET Framework

支援版本:3.0

請參閱

參考

InkEdit 類別

InkEdit 成員

Microsoft.Ink 命名空間

InkCollectorStrokeEventArgs

Cursor

Stroke

Strokes.StrokesAdded