Share via


InkCollector.Stroke (Evento)

Actualización: noviembre 2007

Se produce cuando el usuario termina de dibujar un nuevo trazo en un Tablet PC.

Espacio de nombres:  Microsoft.Ink
Ensamblado:  Microsoft.Ink (en Microsoft.Ink.dll)

Sintaxis

'Declaración
Public Event Stroke As InkCollectorStrokeEventHandler
'Uso
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 no admite eventos.

Comentarios

El controlador de eventos recibe un argumento de tipo InkCollectorStrokeEventArgs que contiene datos sobre este evento.

Cuando se crea un delegado de InkCollectorStrokeEventHandler, se identifica el método que controla el evento. Para asociarlo al controlador de eventos, se debe agregar al evento una instancia del delegado. Siempre que se produce el evento, se llama a su controlador, a menos que se quite el delegado. El interés del evento predeterminado está activado.

El evento Stroke se desencadena incluso cuando se está en modo de selección o de borrado, no solo cuando se inserta una entrada manuscrita. Esto requiere que supervise el modo de edición (de cuya configuración es responsable) y que preste atención a este modo antes de interpretar el evento. La ventaja de este requisito es que se tiene mayor libertad para innovar en la plataforma gracias a un mejor conocimiento de los eventos de la misma.

Nota

El evento Stroke se desencadena cuando el usuario termina de dibujar un trazo, no cuando se agrega un trazo a la colección Strokes. Cuando el usuario empieza a dibujar un trazo, se agrega inmediatamente a la colección Strokes; sin embargo, el evento Stroke no se desencadena hasta que el trazo haya finalizado. Por consiguiente, puede existir un objeto Stroke en la colección Strokes antes de que se desencadene el controlador de eventos Stroke para dicho objeto Stroke.

Ejemplos

En este ejemplo se muestra cómo puede suscribirse al evento CursorDown y al evento Stroke para calcular el período de tiempo que tarda el usuario en crear un trazo.

Al comienzo de un trazo, se desencadena el evento CursorDown. La hora actual se sitúa en la colección ExtendedProperties del objeto Stroke.

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

Cuando se completa el trazo, se desencadena el evento Stroke. La hora de inicio se recupera de la colección ExtendedProperties del objeto Stroke y se usa para calcular el tiempo transcurrido.

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

En este ejemplo, el controlador de eventos del evento Stroke crea un trazo de la sombra creando un nuevo objeto Stroke basado en el objeto Stroke actual y cambiando después el color y la posición del objeto Stroke recién creado.

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

}

Plataformas

Windows Vista

.NET Framework y .NET Compact Framework no admiten todas las versiones de cada plataforma. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.

Información de versión

.NET Framework

Compatible con: 3.0

Vea también

Referencia

InkCollector (Clase)

InkCollector (Miembros)

Microsoft.Ink (Espacio de nombres)

InkCollectorStrokeEventArgs

Cursor

Stroke

Strokes.StrokesAdded