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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Button Error

Status
Not open for further replies.

cvaval

Programmer
Mar 25, 2002
5
HT
Hi,
I Have too Enter Button on a form: a TButton and a bitbtn(On delphi) When press the button 'enter' on the keyboard, I get the execution of the second button.How can I correct this bug?





 
Hi,

I think the focus is on the wrong button. So some where before you want to press the Enter you'll write
button1.setfocus;

Steph
 
Steph's reply is correct - the button with focus always responds to the Enter key. But if no button has focus, i.e. the focus is on a non-button component such as an edit box, then if one of your buttons has its Default property set to True, it will respond to the Enter key. My guess is your second button is probably the "Default" button - check its properties. You may want to set it to False.

If you always want the first button to respond to the Enter key even if a non-button component has the focus at the time, then set the first button's Default property to True.

Mark
 
Also, for the form there's a property called ActiveControl. In the Object Inspector, set this to the button that you want to be the default; that way, when the form gets shown, that button will have focus.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top