Condividi tramite


Evento InkCollector.Stroke

Aggiornamento: novembre 2007

Si verifica quando l'utente completa il disegno di un nuovo tratto su qualsiasi tavoletta.

Spazio dei nomi:  Microsoft.Ink
Assembly:  Microsoft.Ink (in Microsoft.Ink.dll)

Sintassi

'Dichiarazione
Public Event Stroke As InkCollectorStrokeEventHandler
'Utilizzo
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 non supporta gli eventi.

Note

Il gestore eventi riceve un argomento di tipo InkCollectorStrokeEventArgs contenente i dati relativi a questo evento.

Quando si crea un delegato InkCollectorStrokeEventHandler, viene identificato il metodo che gestisce l'evento. Per associare l'evento al gestore eventi in uso, aggiungere all'evento un'istanza del delegato. Il gestore eventi viene chiamato ogni volta che si verifica l'evento, a meno che non si rimuova il delegato. L'interesse dell'evento predefinito è attivato.

L'evento Stroke viene generato anche nella modalità di selezione o di gomma, non solo in caso di inserimento di input penna. È necessario monitorare la modalità di modifica (della cui impostazione è responsabile l'utente) ed essere consapevoli di tale modalità prima di interpretare l'evento. Il vantaggio di questo requisito è una maggiore libertà di innovazione della piattaforma grazie a una maggiore consapevolezza degli eventi della piattaforma.

Nota

L'evento Stroke viene generato quando l'utente completa il disegno di un tratto, non quando un tratto viene aggiunto all'insieme Strokes. Quando l'utente inizia a disegnare un tratto, questo viene aggiunto immediatamente all'insieme Strokes; tuttavia, l'evento Stroke non viene generato fino a che il tratto non è completo. Pertanto, è possibile che un oggetto Stroke sia presente nell'insieme Strokes prima che il gestore generi l'evento Stroke per tale oggetto Stroke.

Esempi

In questo esempio viene illustrato come sottoscrivere l'evento CursorDown e l'evento Stroke per calcolare il tempo richiesto per la creazione di un tratto da parte dell'utente.

All'inizio di un tratto, viene generato l'evento CursorDown. L'ora corrente viene posizionata nell'insieme ExtendedProperties dell'oggetto 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);
}

Al termine del tratto, viene generato l'evento Stroke. L'ora di inizio viene recuperata dall'insieme ExtendedProperties dell'oggetto Stroke e utilizzata per calcolare il tempo trascorso.

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

In questo esempio, il gestore eventi per l'evento Stroke crea un tratto ombreggiato generando un nuovo oggetto Stroke basato sull'oggetto Stroke corrente e modificando quindi il colore e la posizione dell'oggetto Stroke appena creato.

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

}

Piattaforme

Windows Vista

.NET Framework e .NET Compact Framework non supportano tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema di .NET Framework.

Informazioni sulla versione

.NET Framework

Supportato in: 3.0

Vedere anche

Riferimenti

InkCollector Classe

Membri InkCollector

Spazio dei nomi Microsoft.Ink

InkCollectorStrokeEventArgs

Cursor

Stroke

Strokes.StrokesAdded