Board index » delphi » TEdit and the ENTER key

TEdit and the ENTER key

I have a TEdit field on a form that has the focus.  Is there any way that I
can hit the ENTER key and run code that is run when a TButton is pressed?

thanks in advance

Dan Combs

 

Re:TEdit and the ENTER key


On 17 Sep 2002, "Dan" <dancom...@cox.net> wrote:

Quote
> I have a TEdit field on a form that has the focus.  Is there any way
> that I can hit the ENTER key and run code that is run when a TButton
> is pressed?

Write a handler for the Edit's OnKeyPress event:

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then begin
    Key := #0;
    Button1Click(Sender);
  end;
end;

--
-Mike (TeamB)

Other Threads