making a button the default?

  • Thread starter Thread starter Derrick
  • Start date Start date
D

Derrick

Didn't there used to be some property where you could set a button to be the
"default" so that if a user pressed enter with any control in focus, the
button would still get the click event? Some way you could set it as the
"cancel" button too, wasn't there?

Anyway, can you do this with windows forms button?

Thanks in advance!

Derrick
 
Derrick said:
Didn't there used to be some property where you could set a button to be the
"default" so that if a user pressed enter with any control in focus, the
button would still get the click event? Some way you could set it as the
"cancel" button too, wasn't there?

Anyway, can you do this with windows forms button?

Yes, the property is on the form, not the button. After adding the
button to the form, on the form set the AcceptButton property on the
form. You also have a CancelButton property.
 
Tom,

Thanks, should have mentioned this is a "UserControl". I don't see an
AcceptButton property, is that something not available on a control?

Thanks again!

Derrick
 
Derrick said:
Tom,

Thanks, should have mentioned this is a "UserControl". I don't see an
AcceptButton property, is that something not available on a control?

That property is not in Control. For a user control you would need to
handle the key press event for the control looking for the enter or esc
key and behave accordingly.
 
Derrick,
The form's AcceptButton is looking for the IButtonControl interface, if your
UserControl implements IButtonControl and responds appropriately, you should
be able to have a button on your control or the control itself behave as the
Enter (Accept) button for the form.

With effort you might be able to have 2 buttons on a UserControl behave as
the Enter & Cancel buttons for the Form, however I'm not sure how I would
set the respective properties...

Hope this helps
Jay
 
Back
Top