Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default button property in winform app

I have a form that takes user input and then let the user get connected to the sql server. This is happening on button click.But where can I set the property Default button so that the user when clicks enter do the work of that button.

like image 233
Srivastava Avatar asked Nov 25 '10 19:11

Srivastava


People also ask

How do I disable a button in winform?

Enabled = false; this. Controls. Add(DownloadButton); It will make the button fade out and also disabled.

Which property of the button control determines whether the button responds to an event or not?

Its content property is Content. Handle the ButtonBase. Click event to respond when the user clicks a Button. The OnMouseLeftButtonDown method marks the MouseLeftButtonDown event as handled.


4 Answers

It is called AcceptButton now on the form; set that to the button that will be the default button.
Refer to Form.AcceptButton Property

like image 183
BeemerGuy Avatar answered Sep 29 '22 10:09

BeemerGuy


I think you want the "AcceptButton" property at the FORM level... That will expose a combobox of available controls on your form, then select your "button" you want to use as the "Default" button on enter.

like image 43
DRapp Avatar answered Sep 29 '22 10:09

DRapp


I have noticed severally how there is a mix up when it comes to an active button and an accept button. I just came out of it. So, I just thought I add a little option to the answers already given. Obviously, the best answer is;

this.AcceptButton = AcceptButton;

However, if you wish to have the button as an active control, this is what you do;

this.ActiveControl = OkButton;

details: https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.containercontrol.activecontrol?view=netcore-3.1

I hope it is helpful to anyone searching.

like image 23
mw509 Avatar answered Sep 29 '22 12:09

mw509


In addition to Form.AcceptButton property the "OK" button must have the TabOrder property set to 0 and all other controls within the form should have a TabOrder >0.

This can be done using a form resouce contruction kit or by code eg. buttonOK.TabOrder = 0;

like image 42
walterV Avatar answered Sep 29 '22 11:09

walterV