delphi hitting enter

drevet picture drevet · Mar 16, 2011 · Viewed 22.9k times · Source

How can I make an edit box so that when I hit enter with the cursor still in it. Then it goes to that website in the webbrowser which was in the edit box?

can anyone help me?

Answer

Remy Lebeau picture Remy Lebeau · Mar 16, 2011

You should use the OnKeyPress event instead of the OnKeyDown event:

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if ord(Key) = VK_RETURN then
  begin
    Key := #0; // prevent beeping
    WebBrowser1.Navigate(Edit1.Text);
  end;
end;