Share via


InkEditStrokeEventHandler, délégué

Mise à jour : November 2007

Représente la méthode qui gère l'événement Stroke d'un contrôle InkEdit.

Espace de noms :  Microsoft.Ink
Assembly :  Microsoft.Ink (dans Microsoft.Ink.dll)

Syntaxe

'Déclaration
Public Delegate Sub InkEditStrokeEventHandler ( _
    sender As Object, _
    e As InkEditStrokeEventArgs _
)
'Utilisation
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 ne prend pas en charge les délégués.

Paramètres

Notes

  • Lorsque vous créez un délégué InkEditStrokeEventHandler, vous identifiez la méthode qui gère l'événement. Pour associer l'événement au gestionnaire d'événements, ajoutez une instance du délégué à l'événement. Le gestionnaire d'événements est appelé chaque fois qu'un événement se produit, sauf si vous supprimez le délégué.

Exemples

Cet exemple montre comment s'abonner à l'événement Gesture et à l'événement Stroke pour enrichir les fonctionnalités d'un ApplicationGesture.

Lorsque l'événement Gesture se déclenche, il examine le mouvement et l'état actuel du contrôle InkEdit. Si nécessaire, le comportement du mouvement est modifié et l'événement est annulé.

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

Lorsque l'événement Stroke se déclenche, il est annulé si le trait a été utilisé pour générer le mouvement dont le comportement a été modifié dans l'événement Gesture. Cela évite le rendu du trait.

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

Plateformes

Windows Vista

Le .NET Framework et le .NET Compact Framework ne prennent pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.

Informations de version

.NET Framework

Pris en charge dans : 3.0

Voir aussi

Référence

Microsoft.Ink, espace de noms

Cursor

Stroke