Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Make the enter button DO something?? 5

Status
Not open for further replies.

Jonah86

Programmer
Dec 11, 2003
152
US
This is probably a really dumb question, but: Is there any way to have the enter key execute a button's onclick procedure? So when a user is done typing, they just hit the enter button instead of having to click the button to enter text or whatever it is they're doing.

Probably either really easy, or not possible...I'm hoping I'm just retarded and it's really easy:)

Thanks!
 
You can also use the OnKeyDown event handler of objects on the screen or of the form itself (set KeyPreview to True) to handle the Enter key for specific things on the screen. However, the event handlers only fire for the object that currently has focus.

-Dell
 
Or you can use the provided constant (its the same as #13 but looks more meaningful.

procedure TForm1.Button1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key = VK_RETURN then
begin
end;
end;

Steve
Be excellent to each other and Party on!
 
And to actually execute a button's OnClick event, simply call it as you would any other method. If you do nothing with the Sender parameter within your OnClick method then you can pass a nil value, else pass whatever is required.
For example,
Code:
  Button1Click(nil);
OR
Code:
  Button1Click(Self);

Hope this helps!

Clive [infinity]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Wow, thanks a ton everyone. I imagine at least something up there will work:)
 
I personally like to use Button1.Click; better, because it looks like cleaner code

[bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
Great Delphi Websites faq102-5352
 
Bobbafet Yes it works, but not strictly cosha some might say.


Steve
Be excellent to each other and Party on!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top