InkCollector.Stroke 事件
當使用者在任何手寫板上完成繪製新筆劃時發生。
命名空間: 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 事件。這會需要您監視編輯模式 (您必須負責其設定),並且在解譯事件之前注意模式。這個需求的優點是透過覺察平台事件,獲得平台創新的更大自由。
注意事項: |
---|
在使用者完成繪製筆劃時,而不是在筆劃加入至 Strokes 集合時,會引發 Stroke 事件。使用者開始繪製筆劃時,筆劃會被立即加入至 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