Delphi 2010 最抢眼的新功能可能就是支持"触摸屏"了, 它包括一个 可触控的软键盘 和识别不同的触屏手势.

因为手势同时支持鼠标, 所以没有触摸屏的我也可以尝试一下其大多数的功能.

首次尝试的步骤:

1、加 TGestureManager 控件如窗体: GestureManager1;

2、设置窗体属性 Touch.GestureManager := GestureManager1; {下面程序是在设计时指定的属性}

3、添加窗体的 OnGesture 事件, 随便写点什么;

4、然后运行程序, 用鼠标随便在窗体上 "划" 几下... 第一个测试程序完成了!

测试代码:

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
  Self.Touch.GestureManager := GestureManager1; {可在设计时指定}
end;

procedure TForm1.FormGesture(Sender: TObject;
  const EventInfo: TGestureEventInfo; var Handled: Boolean);
begin
  ShowMessage(Sender.ClassName + '_Gesture');
end;

end.


现在程序可以 "感知手势" 了, 怎么 "识别手势" 呢?

Delphi 把可以识别的手势分成了 3 类: 标准手势、自定义手势、交互手势(InteractiveGestures).

其中的交互手势用鼠标不好模拟, 可能只能用于触摸屏;

Delphi 预定义了 34 种标准手势, 并定义成 TStandardGesture 枚举类型:
TStandardGesture = (
  sgLeft            = sgiLeft,
  sgRight           = sgiRight,
  sgUp              = sgiUp,
  sgDown            = sgiDown,
  sgUpLeft          = sgiUpLeft,
  sgUpRight         = sgiUpRight,
  sgDownLeft        = sgiDownLeft,
  sgDownRight       = sgiDownRight,
  sgLeftUp          = sgiLeftUp,
  sgLeftDown        = sgiLeftDown,
  sgRightUp         = sgiRightUp,
  sgRightDown       = sgiRightDown,
  sgUpDown          = sgiUpDown,
  sgDownUp          = sgiDownUp,
  sgLeftRight       = sgiLeftRight,
  sgRightLeft       = sgiRightLeft,
  sgUpLeftLong      = sgiUpLeftLong,
  sgUpRightLong     = sgiUpRightLong,
  sgDownLeftLong    = sgiDownLeftLong,
  sgDownRightLong   = sgiDownRightLong,
  sgScratchout      = sgiScratchout,
  sgTriangle        = sgiTriangle,
  sgSquare          = sgiSquare,
  sgCheck           = sgiCheck,
  sgCurlicue        = sgiCurlicue,
  sgDoubleCurlicue  = sgiDoubleCurlicue,
  sgCircle          = sgiCircle,
  sgDoubleCircle    = sgiDoubleCircle,
  sgSemiCircleLeft  = sgiSemiCircleLeft,
  sgSemiCircleRight = sgiSemiCircleRight,
  sgChevronUp       = sgiChevronUp,
  sgChevronDown     = sgiChevronDown,
  sgChevronLeft     = sgiChevronLeft,
  sgChevronRight    = sgiChevronRight);


注意: 每个枚举项都对应了一个常数值(譬如: 枚举项 sgLeft 对应 sgiLeft, sgiLeft 是之前定义好的常数);

应记下常数的命名规律, 后面会经常用到它们, 以区别触发的是哪个手势, 譬如:

if EventInfo.GestureID = sgiLeft then ...


下面是从 docwiki.embarcadero.com/RADStudio/en/TStandardGesture_Enum 拷过来的标准手势的图示:

Enum Symbol
sgLeft image:64GestLeft.gif
sgRight image:64GestRight.gif
sgUp image:64GestUp.gif
sgDown image:64GestDown.gif
sgUpLeft image:64GestUpLeft.gif
sgUpRight image:64GestUpRight.gif
sgDownLeft image:64GestDownLeft.gif
sgDownRight image:64GestDownRight.gif
sgLeftUp image:64GestLeftUp.gif
sgLeftDown image:64GestLeftDown.gif
sgRightUp image:64GestRightUp.gif
sgRightDown image:64GestRightDown.gif
sgUpDown image:64GestUpDown.gif
sgDownUp image:64GestDownUp.gif
sgLeftRight image:64GestLeftRight.gif
sgRightLeft image:64GestRightLeft.gif
sgUpLeftLong image:64GestUpLeftLong.gif
sgUpRightLong image:64GestUpRightLong.gif
sgDownLeftLong image:64GestDownLeftLong.gif
sgDownRightLong image:64GestDownRightLong.gif
sgScratchout image:64GestScratchOut.gif
sgTriangle image:64GestTriangle.gif
sgSquare image:64GestSquare.gif
sgCheck image:64GestCheck.gif
sgCurlicue image:64GestCurlicue.gif
sgDoubleCurlicue image:64GestDoubleCurlicue.gif
sgCircle image:64GestCircle.gif
sgDoubleCircle image:64GestDoubleCircle.gif
sgSemiCircleLeft image:64GestSemiCircleLeft.gif
sgSemiCircleRight image:64GestSemiCircleRight.gif
sgChevronUp image:64GestChevronUp.gif
sgChevronDown image:64GestChevronDown.gif
sgChevronLeft image:64GestChevronLeft.gif
sgChevronRight image:64GestChevronRight.gif


posted on 2009-10-21 09:32  万一  阅读(9053)  评论(0编辑  收藏  举报