Re:Using the Return Key instead of Tab
For most components you can use the OnKeyPress event to trap the Enter
key and then do what you want with it. The following is an example of how
to trap the Enter key in a TEdit and sent the focus to the next control in
the tab order. It also kills the annoying beep. You can use the same
event for more than one control on a form by setting it using the object
inspector.
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then {#13 is the enter key}
begin
Key := #0; {Kill the key so there is no beep}
PostMessage(Handle, wm_NextDlgCtl, 0, 0); {Send focus to the next
control}
end;
end;
If you wanted this to work for all controls on a form (say 4 or 5 TEdits)
then you would set the forms KeyPreview property to true for the form and
then put the same code in the forms OnKeyPress event. I.e.:
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then
begin
Key := #0;
PostMessage(Handle, wm_NextDlgCtl, 0, 0);
end;
end;
Hope this helps!
--
Rodney E Geraghty
GERA-Tech
Ottawa, Canada
gera...@ibm.net
a_adaram...@my-dejanews.com wrote in article
<6m9771$d4...@nnrp1.dejanews.com>...
Quote
> Does anyone know how to use the Return key to move between text boxes on
a
> form at runtime, instead of using the Tab key. I write programs which
require
> a lot of fields on different forms, I would like to be able to let users
use
> the Return key to navigate the form, and I would like to be able to do
this
> without writing too much code.
> Thanks.
> -----== Posted via Deja News, The Leader in Internet Discussion ==-----
> http://www.dejanews.com/ Now offering spam-free web-based newsreading