Recent

Author Topic: How do I use Enter key i/o Tab to traverse between textboxes in a form  (Read 17549 times)

Goodman H__

  • Full Member
  • ***
  • Posts: 130
Greetings to everybody!

In Delphi I can write code in form's keyPress event(set form's keypreview:=true):
Code: [Select]
if key=#13 then
perform(wm_nextDlgCtrl,0,0);
end;
How can I do the same in FP?And what's the cross-platform solution also?

Thanks a lot for your help in advance.

Regards,
Sam
« Last Edit: May 22, 2010, 04:45:08 am by Goodman H__ »
fpc:2.6.1 Lazarus:1.1 SVN39277
OS:win 7

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Code: [Select]
uses LCLType;

procedure TForm1.FormKeyDown(Sender:TObject;var Key:Word;Shift:TShiftState);
begin
  if Key=VK_Return then SelectNext(ActiveControl,True,True);
end;

zeljko

  • Hero Member
  • *****
  • Posts: 1596
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Greetings to everybody!

In Delphi I can write code in form's keyPress event(set form's keypreview:=true):
Code: [Select]
if key=#13 then
perform(wm_nextDlgCtrl,0,0);
end;
How can I do the same in FP?And what's the cross-platform solution also?

if Key = #13 then
  SelectNext(ActiveControl, True, True)

Regards,
Sam

Goodman H__

  • Full Member
  • ***
  • Posts: 130
Code: [Select]
uses LCLType;

procedure TForm1.FormKeyDown(Sender:TObject;var Key:Word;Shift:TShiftState);
begin
  if Key=VK_Return then SelectNext(ActiveControl,True,True);
end;

Thank you.It works.

But there is a little difference.Based on the above code,all controls can traverse by enter key with no problem,but when nagivate to a button,press enter does not fire the button's event,just go to the next control.If I want to fire the button's event,I need to press blank key.Not the same in delphi though,but it works.
fpc:2.6.1 Lazarus:1.1 SVN39277
OS:win 7

 

TinyPortal © 2005-2018