本例嘗試在 OnGesture 事件中響應 sgLeft、sgRight 手勢; 操作步驟:
1、加 TGestureManager 控件如窗體: GestureManager1;
2、設置窗體屬性 Touch.GestureManager := GestureManager1;
3、添加窗體的 OnCreate 事件, 寫: Touch.StandardGestures := [sgLeft, sgRight];
4、添加窗體的 OnGesture 事件, 寫響應代碼.
上面的步驟 3 的目的是指定准備要接受識別的動作, 這在設計時選定比較方便:
測試代碼:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, GestureMgr;
type
TForm1 = class(TForm)
GestureManager1: TGestureManager;
procedure FormCreate(Sender: TObject);
procedure FormGesture(Sender: TObject; const EventInfo: TGestureEventInfo;
var Handled: Boolean);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Touch.StandardGestures := [sgLeft, sgRight];
end;
procedure TForm1.FormGesture(Sender: TObject;
const EventInfo: TGestureEventInfo; var Handled: Boolean);
begin
case EventInfo.GestureID of
sgiLeft : ShowMessage('Left');
sgiRight : ShowMessage('Right');
end;
end;
end.