【使用上下键控制控件的选择】
Taborder Tabstop:
这组表识号本来是用来表示组件的按键顺序以及在该组件上是否停留的标识号。但是如果在某些时候稍微重视一下的话,将会事半功倍。下面略举一例:桌面上有几个编辑框,用户希望按回车键、上下方向键而不是TAB在其间来回游动。
【属性设置】
Form.keypreview = TRUE
edt1.TabStop = TRUE
edt2.TabStop = TRUE
edt3.TabStop = TRUE
edt1.TabOrder = 0
edt1.TabOrder = 1
edt1.TabOrder = 2
【代码】
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) edt1: TEdit; edt2: TEdit; edt3: TEdit; procedure FormCreate(Sender: TObject); private procedure Tab(sender:Tobject;var key:word;shift:TShiftState); { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin edt1.OnKeyDown := Tab; edt2.OnKeyDown := Tab; edt3.OnKeyDown := Tab; end; procedure TForm1.Tab(sender:TObject;var key:Word;Shift:TShiftState); begin if (key=VK_DOWN) or (key=13) then SelectNext(ActiveControl,True,True); if key=vk_up then SelectNext(ActiveControl,False,false); key:= 0; end; end.