Delphi 2010 最搶眼的新功能可能就是支持"觸摸屏"了, 它包括一個(gè) 可觸控的軟鍵盤 和識(shí)別不同的觸屏手勢(shì). 因?yàn)槭謩?shì)同時(shí)支持鼠標(biāo), 所以沒有觸摸屏的我也可以嘗試一下其大多數(shù)的功能. 首次嘗試的步驟: 1、加 TGestureManager 控件如窗體: GestureManager1; 2、設(shè)置窗體屬性 Touch.GestureManager := GestureManager1; {下面程序是在設(shè)計(jì)時(shí)指定的屬性} 3、添加窗體的 OnGesture 事件, 隨便寫點(diǎn)什么; 4、然后運(yùn)行程序, 用鼠標(biāo)隨便在窗體上 "劃" 幾下... 第一個(gè)測(cè)試程序完成了! 測(cè)試代碼: 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; {可在設(shè)計(jì)時(shí)指定} end; procedure TForm1.FormGesture(Sender: TObject; const EventInfo: TGestureEventInfo; var Handled: Boolean); begin ShowMessage(Sender.ClassName + '_Gesture'); end; end. 現(xiàn)在程序可以 "感知手勢(shì)" 了, 怎么 "識(shí)別手勢(shì)" 呢? Delphi 把可以識(shí)別的手勢(shì)分成了 3 類: 標(biāo)準(zhǔn)手勢(shì)、自定義手勢(shì)、交互手勢(shì)(InteractiveGestures). 其中的交互手勢(shì)用鼠標(biāo)不好模擬, 可能只能用于觸摸屏; Delphi 預(yù)定義了 34 種標(biāo)準(zhǔn)手勢(shì), 并定義成 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); 注意: 每個(gè)枚舉項(xiàng)都對(duì)應(yīng)了一個(gè)常數(shù)值(譬如: 枚舉項(xiàng) sgLeft 對(duì)應(yīng) sgiLeft, sgiLeft 是之前定義好的常數(shù)); 應(yīng)記下常數(shù)的命名規(guī)律, 后面會(huì)經(jīng)常用到它們, 以區(qū)別觸發(fā)的是哪個(gè)手勢(shì), 譬如: if EventInfo.GestureID = sgiLeft then ... 下面是從 docwiki./RADStudio/en/TStandardGesture_Enum 拷過來的標(biāo)準(zhǔn)手勢(shì)的圖示: |
|