Share via


InkEditStrokeEventHandler-Delegat

Stellt die Methode dar, die das Stroke-Ereignis eines InkEdit-Steuerelements behandelt.

Namespace:  Microsoft.Ink
Assembly:  Microsoft.Ink (in Microsoft.Ink.dll)

Syntax

'Declaration
Public Delegate Sub InkEditStrokeEventHandler ( _
    sender As Object, _
    e As InkEditStrokeEventArgs _
)
'Usage
Dim instance As New InkEditStrokeEventHandler(AddressOf HandlerMethod)
public delegate void InkEditStrokeEventHandler(
    Object sender,
    InkEditStrokeEventArgs e
)
public delegate void InkEditStrokeEventHandler(
    Object^ sender, 
    InkEditStrokeEventArgs^ e
)
/** @delegate */
public delegate void InkEditStrokeEventHandler(
    Object sender,
    InkEditStrokeEventArgs e
)
JScript unterstützt keine Delegaten.

Parameter

Hinweise

  • Beim Erstellen eines InkEditStrokeEventHandler-Delegaten bestimmen Sie die Methode für die Ereignisbehandlung. Um dem Ereignishandler das Ereignis zuzuordnen, fügen Sie dem Ereignis eine Instanz des Delegaten hinzu. Der Ereignishandler wird bei jedem Eintreten des Ereignisses aufgerufen, sofern der Delegat nicht entfernt wird.

Beispiele

In diesem Beispiel wird veranschaulicht, wie Sie das Gesture-Ereignis und das Stroke-Ereignis abonnieren können, um die Funktionalität einer ApplicationGesture zu erweitern.

Wenn das Gesture-Ereignis ausgelöst wird, werden die Stiftbewegung und der aktuelle Zustand des InkEdit-Steuerelements untersucht. Gegebenenfalls wird das Verhalten der Stiftbewegung geändert, und das Ereignis wird abgebrochen.

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

Wenn das Stroke-Ereignis für den Strich ausgelöst wird, mit dem die Stiftbewegung generiert wurde, deren Verhalten im Gesture-Ereignis geändert wurde, wird das Ereignis abgebrochen. Dies verhindert das Rendern des Strichs.

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

Plattformen

Windows Vista

.NET Framework und .NET Compact Framework unterstützen nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen für .NET Framework.

Versionsinformationen

.NET Framework

Unterstützt in: 3.0

Siehe auch

Referenz

Microsoft.Ink-Namespace

Cursor

Stroke