很简单的一个问题:一个Form里有很多Edit输入框,它们的TabOrder顺序都设置好了,想按回车键自动转到下一个.怎样实现?
以前的都是分别在每个EDIT框的OnKeyPress里面写代码:
if key = #13 then
edit2.setfocus;
可不可以在Form的OnKeyPress里写代码.
if key = #13 then
setNextFocus; 类似于这样的方法来实现?
因为在每个EDIT框都写代码太麻烦了.
[解决办法]
orm的Keypreview 设为True
再在Form的Onkeypress事件中写
if (key=#13) then
begin
key=#0;
perform(WM_NEXTDLGCTL,0,0);
end;
[解决办法]
还可以用这个
procedure SelectNext(CurControl: TWinControl; GoForward, CheckTabStop: Boolean);
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
if (key=#13) then
begin
key:=#0;
SelectNext(ActiveControl, True, True);
end;
end;
GoForward, true:向前找,false:向后找
CheckTabStop:true 如果Edit 的tabstop为false,则不会选择它,直接跳到下一个.
false 不考虑tabstop