Board index » delphi » TEdit - changing focus on Enter key

TEdit - changing focus on Enter key

How can i make focus shift from one TEdit component to another when
the user presses the Enter key after entering the string?

I tried event OnKeyDown and SetFocusedControl, but this doesn't seem to
work...

Anyone have any ideas?  (using delphi 3)

            Thanks,
            Magnus M.

 

Re:TEdit - changing focus on Enter key


  Well, it does if you do it write...  Group ALL your TEdits together, and
use the following code (they can all use this same function):

  OnKeyDown:

  if key = #13 then begin
    key := #0;  // kill beep...
    perform(WM_NEXTDLGCTL, 0, 0);  // jumps to next control...
  end;

--
Jason Wallace
SL Software
Dark...@SLSoftware.reno.nv.us
--
"We are Microsoft.  Resistance is Futile.  You will be Assimiliated."

Quote
John. M wrote in message <895168284.456263@mn8>...
>How can i make focus shift from one TEdit component to another when
>the user presses the Enter key after entering the string?

>I tried event OnKeyDown and SetFocusedControl, but this doesn't seem to
>work...

>Anyone have any ideas?  (using delphi 3)

>            Thanks,
>            Magnus M.

Re:TEdit - changing focus on Enter key


Quote
Magnus M. wrote:
>How can i make focus shift from one TEdit component to another when
>the user presses the Enter key after entering the string?

What you have to do is capture the return key in the OnKeyPress
eventhandler, by for example using the following code.

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then begin
    Key := #0;  // Captures the keypress
    Edit2.SetFocus; // Shifts focus to the next EditBox
  end;
end;

Joachim Calvert (jcalv...@hem.passagen.se)

Re:TEdit - changing focus on Enter key


On Thu, 14 May 1998 19:51:21 +0200, "John. M" <nos...@nospam.com>
wrote:

Quote
>How can i make focus shift from one TEdit component to another when
>the user presses the Enter key after entering the string?

>I tried event OnKeyDown and SetFocusedControl, but this doesn't seem to
>work...

>Anyone have any ideas?  (using delphi 3)

>            Thanks,
>            Magnus M.

hi magnus,

an Exp. for Enter to TAB,

  form1 = class(Tform)
    procedure Form1_onKeyPress(Sender: TObject; var Key: Char);
 end;

procedure Form1.Form1_onKeyDown(Sender : TObject; var Key : Char);
begin
  if (Key = #13) then                                 (* Enter *)
  begin
     Key := #0;
     PostMessage(Handle, WM_NEXTDLGCTL,0,0);
  end;
end;

   Form1.KeyPreview := TRUE;  // not forget this
.
bye J?rg

Re:TEdit - changing focus on Enter key


This will not work in OnKeyDown since key is of type word (this
requires virtual key codes) and not a character. In OnKeyDown replace
#13 by VK_RETURN and leave out key=#0 line. In OnKeyPressed put the
code less the perform line. Otherwise put the lot in OnKeyPressed.
You need to set the Tab order to make sure the cursor moves in the
required order. Note that if you want the cycle to return to the first
edit box from the last you need to replace perform by Edit1.setfocus
for the last box in the sequence.

Quote
>  Well, it does if you do it write...  Group ALL your TEdits
together, and
>use the following code (they can all use this same function):

>  OnKeyDown:

>  if key = #13 then begin
>    key := #0;  // kill beep...
>    perform(WM_NEXTDLGCTL, 0, 0);  // jumps to next control...
>  end;

Other Threads