InkEditGestureEventHandler 委派
表示處理 InkEdit 控制項之 Gesture 事件的方法。
命名空間: Microsoft.Ink
組件: Microsoft.Ink (在 Microsoft.Ink.dll 中)
語法
'宣告
Public Delegate Sub InkEditGestureEventHandler ( _
sender As Object, _
e As InkEditGestureEventArgs _
)
'用途
Dim instance As New InkEditGestureEventHandler(AddressOf HandlerMethod)
public delegate void InkEditGestureEventHandler(
Object sender,
InkEditGestureEventArgs e
)
public delegate void InkEditGestureEventHandler(
Object^ sender,
InkEditGestureEventArgs^ e
)
/** @delegate */
public delegate void InkEditGestureEventHandler(
Object sender,
InkEditGestureEventArgs e
)
JScript 不支援委派。
參數
- sender
型別:System.Object
這個事件的來源 InkEdit 控制項。
- e
型別:Microsoft.Ink.InkEditGestureEventArgs
包含事件資料的 InkEditGestureEventArgs 物件。
備註
「應用程式筆勢」是應用程式內支援的筆勢。
為了讓這個事件發生,InkEdit 控制項必須與一組應用程式筆勢有關聯。若要設定 InkEdit 控制項與一組筆勢的關聯,請呼叫 InkEdit 控制項的 SetGestureStatus 方法。
如需特定的應用程式筆勢清單,請參閱 ApplicationGesture 列舉型別。如需應用程式筆勢的詳細資訊,請參閱Using Gestures和 Command Input on the Tablet PC。
在建立 InkEditGestureEventHandler 委派 (Delegate) 時,您會識別處理事件的方法。若要使事件與您的事件處理常式產生關聯,請將委派的執行個體 (Instance) 加入至事件。除非您移除委派,否則每當事件發生時就會呼叫事件處理常式。
在 InkEdit 控制項中,只有當筆勢是在上次呼叫 Recognize 方法或上次引發辨識逾時之後的第一個筆劃時,才會引發 Gesture 事件。
如果取消 Gesture 事件,則會針對引發 Gesture 事件的 Stroke 物件引發 Stroke 事件。
InkEdit 控制項不會辨識多個筆劃的筆勢。
InkEdit 控制項具有下列筆勢的預設關聯與動作:
筆勢 |
動作 |
---|---|
向左下,向左下拉長 |
ENTER |
向右 |
空格鍵 |
向左 |
退格鍵 |
向右上,向右上拉長 |
TAB |
若要改變筆勢的預設動作:
在 InkEditStrokeEventHandler 委派中,針對引發已取消之 Gesture 事件的 Stroke 物件取消 Stroke 事件。
範例
這個範例示範如何訂閱 Gesture 事件及 Stroke 事件,以便擴充 ApplicationGesture 的功能。
當 Gesture 事件引發時,會檢查筆勢和 InkEdit 控制項的目前狀態。必要時,會修改筆勢的行為並取消事件。
Private Sub mInkEdit_Gesture(ByVal sender As Object, ByVal e As InkEditGestureEventArgs)
' There might be more than one gesture passed in InkEditGestureEventArgs
' The gestures are arranged in order of confidence from most to least
' This event handler is only concerned with the first (most confident) gesture
' and only if the gesture is ApplicationGesture.Left with strong confidence
Dim G As Gesture = e.Gestures(0)
If (ApplicationGesture.Left = G.Id And RecognitionConfidence.Strong = G.Confidence) Then
Dim pInkEdit As InkEdit = DirectCast(sender, InkEdit)
' by default, ApplicationGesture.Left maps to Backspace
' If the insertion point is at the beginning of the text
' and there is no text selected, then Backspace does not do anything.
' In this case, we will alter the gesture to map to Delete instead
If (0 = pInkEdit.SelectionStart And 0 = pInkEdit.SelectionLength And pInkEdit.Text.Length > 0) Then
' take out the first character of the string
pInkEdit.Text = pInkEdit.Text.Remove(0, 1)
' save the stroke ID in a class level var for use in the Stroke event
Me.mStrokeID = e.Strokes(0).Id
' cancel the gesture so it won't perform the default action
e.Cancel = True
End If
End If
End Sub
private void mInkEdit_Gesture(object sender, InkEditGestureEventArgs e)
{
// There might be more than one gesture passed in InkEditGestureEventArgs
// The gestures are arranged in order of confidence from most to least
// This event handler is only concerned with the first (most confident) gesture
// and only if the gesture is ApplicationGesture.Left with strong confidence
Gesture G = e.Gestures[0];
if (ApplicationGesture.Left == G.Id && RecognitionConfidence.Strong == G.Confidence)
{
InkEdit pInkEdit = (InkEdit)sender;
// by default, ApplicationGesture.Left maps to Backspace
// If the insertion point is at the beginning of the text
// and there is no text selected, then Backspace does not do anything.
// In this case, we will alter the gesture to map to Delete instead
if (0 == pInkEdit.SelectionStart && 0 == pInkEdit.SelectionLength && pInkEdit.Text.Length > 0)
{
// take out the first character of the string
pInkEdit.Text = pInkEdit.Text.Remove(0, 1);
// save the stroke ID in a class level var for use in the Stroke event
this.mStrokeID = e.Strokes[0].Id;
// cancel the gesture so it won't perform the default action
e.Cancel = true;
}
}
}
當 Stroke 事件引發時,如果筆劃是用來產生筆勢的筆劃,但是筆勢的行為已在 Gesture 事件中修改過,則會取消這個事件。這會使筆劃無法呈現。
Private Sub mInkEdit_Stroke(ByVal sender As Object, ByVal e As InkEditStrokeEventArgs)
e.Cancel = (e.Stroke.Id = Me.mStrokeID)
End Sub
private void mInkEdit_Stroke(object sender, InkEditStrokeEventArgs e)
{
e.Cancel = (e.Stroke.Id == this.mStrokeID);
}
平台
Windows Vista
.NET Framework 和 .NET Compact Framework 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱 .NET Framework 系統需求。
版本資訊
.NET Framework
支援版本:3.0