在CLX TEdit的KeyPress事件中截取TAB键 [英] Intercept TAB key in KeyPress event of a CLX TEdit
问题描述
如何截取TEdit Control的KeyPress事件中的TAB键?
编辑事件不适用于导航键 Tab
,因为这些不会触发键盘事件。唯一指出这个事实的地方。 Delphi帮助TCustomForm.KeyPreview
要在表格和TMemo上测试put 3 TEdit(CLX)。
标签顺序是Edit1,Edit2,Edit3
唯一的事件你可以使用的是KeyUp事件
procedure TForm1.Edit1KeyUp(Sender:TObject; var Key:Word;
Shift:TShiftState);
begin
Memo1.Lines.Add('Edit1KeyUp');
结束
程序TForm1.Edit2KeyUp(发件人:TObject; var Key:Word;
Shift:TShiftState);
begin
Memo1.Lines.Add('Edit2KeyUp');
结束
程序TForm1.Edit3KeyUp(发件人:TObject; var Key:Word;
Shift:TShiftState);
begin
Memo1.Lines.Add('Edit3KeyUp');
如果Key = VK_TAB然后开始
Edit2.SetFocus;
结束
结束
- 将光标放在Edit2输入字段
-
按转移标签
- 光标移动到字段edit1
-
Memo1显示
Edit1KeyUp
Edit1KeyUp
-
按选项卡
- 光标移动到字段edit2
-
Memo1显示
Edit2KeyUp
- p>按选项卡
- 游标尝试移动到字段edit3
- ,使用命令
Edit2.SetFocus;
我们将光标返回到edit2 -
Memo1显示
Edit3KeyUp
< >所以用TAB键用户永远不能离开edit2
例如:在Edit3KeyUp事件中,您可以将#9添加到Edit2 .Text。
如果Key = VK_TAB然后开始
Edit2.SetFocus;
Edit2.Text:= Edit2.Text +#9 +'< - a Tab here';
结束
I have a TEdit (VisualCLX Component) and I want to override the behaviour of the TAB Key in the onKeyPress event, but if I try to intercept the TAB key in the KeyPress event it doesn't work because the event is not fired when the tab key is pressed on the TEdit.
How can I intercept the TAB Key on KeyPress event of TEdit Control ?
Edit Events does not apply to navigation keys Tab
as these do not trigger keyboard events. The only place which points to this fact. Delphi Help TCustomForm.KeyPreview
To test put 3 TEdit (CLX) on a form And a TMemo.
The tab order is Edit1, Edit2, Edit3
The only event you can use is the KeyUp Event
procedure TForm1.Edit1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
Memo1.Lines.Add('Edit1KeyUp');
end;
procedure TForm1.Edit2KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
Memo1.Lines.Add('Edit2KeyUp');
end;
procedure TForm1.Edit3KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
Memo1.Lines.Add('Edit3KeyUp');
if Key = VK_TAB then begin
Edit2.SetFocus;
end;
end;
- put the cursor in Edit2 input field
press shift tab
- The cursor moves to the field edit1
Memo1 shows
Edit1KeyUp
Edit1KeyUp
press tab
- The cursor moves to the field edit2
Memo1 shows
Edit2KeyUp
press tab
- The cursor tries to move to the field edit3
- with the command
Edit2.SetFocus;
we send the cursor back to edit2 Memo1 shows
Edit3KeyUp
So with the TAB key the user never can leave edit2
for example : In the Edit3KeyUp event you can add a #9 to to Edit2.Text.
if Key = VK_TAB then begin
Edit2.SetFocus;
Edit2.Text := Edit2.Text+#9+'<- a Tab here';
end;
这篇关于在CLX TEdit的KeyPress事件中截取TAB键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!