다음을 통해 공유


InkCollector.Stroke 이벤트

업데이트: 2007년 11월

사용자가 태블릿에서 새 스트로크를 그리는 작업을 마칠 때 발생합니다.

네임스페이스:  Microsoft.Ink
어셈블리:  Microsoft.Ink(Microsoft.Ink.dll)

구문

‘선언
Public Event Stroke As InkCollectorStrokeEventHandler
‘사용 방법
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에서는 이벤트를 지원하지 않습니다.

설명

이벤트 처리기는 이 이벤트에 대한 데이터가 들어 있는 InkCollectorStrokeEventArgs 형식의 인수를 받습니다.

InkCollectorStrokeEventHandler 대리자를 만들 때는 이벤트를 처리할 메서드를 식별합니다. 이벤트를 이벤트 처리기와 연결하려면 대리자의 인스턴스를 해당 이벤트에 추가합니다. 대리자를 제거하지 않는 경우 이벤트가 발생할 때마다 이벤트 처리기가 호출됩니다. 이벤트 관심도는 기본적으로 설정됩니다.

잉크를 삽입하는 경우뿐만 아니라 선택 또는 지우기 모드인 경우에도 Stroke 이벤트가 발생합니다. 따라서 사용자가 설정하는 편집 모드는 사용자가 직접 모니터링해야 하며 이벤트를 해석하기 전에 모드를 알고 있어야 합니다. 이러한 요구 사항을 적용하면 플랫폼 이벤트를 더 효율적으로 인식하여 플랫폼을 보다 자유롭게 활용할 수 있습니다.

참고

Stroke 이벤트는 스트로크가 Strokes 컬렉션에 추가될 때가 아니라 사용자가 스트로크를 그리는 작업을 마칠 때 발생합니다. 사용자가 스트로크 그리기를 처음 시작하면 스트로크가 Strokes 컬렉션에 즉시 추가됩니다. 그러나 스트로크가 완료될 때까지는 Stroke 이벤트가 발생하지 않습니다. 그러므로 Stroke 개체는 Stroke 이벤트 처리기가 해당 Stroke 개체에 대해 발생하기 전에 이미 Strokes 컬렉션에 있을 수도 있습니다.

예제

이 예제에서는 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에서 지원

참고 항목

참조

InkCollector 클래스

InkCollector 멤버

Microsoft.Ink 네임스페이스

InkCollectorStrokeEventArgs

Cursor

Stroke

Strokes.StrokesAdded