次の方法で共有


InkCollectorStrokeEventHandler デリゲート

InkCollector オブジェクトの Stroke イベントを処理するメソッドを表します。

名前空間 :  Microsoft.Ink
アセンブリ :  Microsoft.Ink (Microsoft.Ink.dll 内)

構文

'宣言
Public Delegate Sub InkCollectorStrokeEventHandler ( _
    sender As Object, _
    e As InkCollectorStrokeEventArgs _
)
'使用
Dim instance As New InkCollectorStrokeEventHandler(AddressOf HandlerMethod)
public delegate void InkCollectorStrokeEventHandler(
    Object sender,
    InkCollectorStrokeEventArgs e
)
public delegate void InkCollectorStrokeEventHandler(
    Object^ sender, 
    InkCollectorStrokeEventArgs^ e
)
/** @delegate */
public delegate void InkCollectorStrokeEventHandler(
    Object sender,
    InkCollectorStrokeEventArgs e
)
JScript では、デリゲートは使用できません。

パラメータ

解説

InkCollectorStrokeEventHandler デリゲートを作成する場合は、イベントを処理するメソッドを指定します。イベントをイベント ハンドラに関連付けるには、デリゲートのインスタンスをイベントに追加します。デリゲートを削除しない限り、そのイベントが発生すると常にイベント ハンドラが呼び出されます。既定のイベント対象は有効です。

Stroke イベントは、インクを挿入するときのみではなく選択モードまたは消去モードの場合でも発生します。このためには編集モードを監視し (設定する必要があります)、イベントを解釈する前にモードを認識する必要があります。この要件の利点はプラットフォーム イベントの認識がより容易になることにより、プラットフォーム上での新しい技術の導入がより可能になることです。

この例では、CursorDown イベント、および Stroke イベントにサブスクライブし、ユーザーがストロークを作成する際にかかる時間の長さを計算する方法を示します。

ストロークの始点で、CursorDown イベントが発生します。現在の時刻は、Stroke オブジェクトの ExtendedProperties コレクションに格納されます。

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

ストロークが完了すると、Stroke イベントが発生します。Stroke オブジェクトの ExtendedProperties コレクションから開始時刻が取得され、経過時間を計算するために使用されます。

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

この例では、Stroke イベントのイベント ハンドラが、現在の Stroke オブジェクトに基づいて、新しい Stroke オブジェクトを作成し、新しく作成された Stroke オブジェクトの色および位置を変更して、シャドウ ストロークを作成します。

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

}

プラットフォーム

Windows Vista

.NET Framework および .NET Compact Framework では、各プラットフォームのすべてのバージョンはサポートしていません。サポートされているバージョンについては、「.NET Framework システム要件」を参照してください。

バージョン情報

.NET Framework

サポート対象 : 3.0

参照

参照

Microsoft.Ink 名前空間

Cursor

InkOverlay.StrokesDeleted

Stroke

Strokes.StrokesAdded