InkPicture.CursorDown 事件
當游標筆尖接觸到數位手寫板表面時發生。
命名空間: Microsoft.Ink
組件: Microsoft.Ink (在 Microsoft.Ink.dll 中)
語法
'宣告
Public Event CursorDown As InkCollectorCursorDownEventHandler
'用途
Dim instance As InkPicture
Dim handler As InkCollectorCursorDownEventHandler
AddHandler instance.CursorDown, handler
public event InkCollectorCursorDownEventHandler CursorDown
public:
event InkCollectorCursorDownEventHandler^ CursorDown {
void add (InkCollectorCursorDownEventHandler^ value);
void remove (InkCollectorCursorDownEventHandler^ value);
}
/** @event */
public void add_CursorDown (InkCollectorCursorDownEventHandler value)
/** @event */
public void remove_CursorDown (InkCollectorCursorDownEventHandler value)
JScript 不支援事件。
備註
事件處理常式會接收 InkCollectorCursorDownEventArgs 型別的引數,其中包含這個事件的相關資料。
在建立 InkCollectorCursorDownEventHandler 委派時,您要識別處理事件的方法。若要使事件與您的事件處理常式產生關聯,請將委派的執行個體加入至事件。除非您移除委派,否則每當事件發生時就會呼叫事件處理常式。基於效能考量,相關事件的預設是關閉的,但會在您加入事件處理常式時自動開啟。
如果事件處理常式中執行太多程式碼,則這個事件可能對筆墨效能造成負面影響。若要改善即時筆墨效能,請在使用筆墨書寫時隱藏滑鼠游標。若要執行這項操作,請在 MouseDown 事件處理常式中隱藏滑鼠游標,並且在 MouseUp 事件處理常式中顯示滑鼠游標。
範例
這個範例會示範如何訂閱 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();
}
}
平台
Windows Vista
.NET Framework 和 .NET Compact Framework 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱 .NET Framework 系統需求。
版本資訊
.NET Framework
支援版本:3.0
請參閱
參考
InkCollectorCursorDownEventArgs