In my C# WinForms program, I have a form that has only a single Button control on it. By default, that Button control receives the focus on the form. But I don't want the Button to ever get focus.
Is there a solution, even one that would require a call to an unmanaged API?
In your form Load
event you can set the focus on some other control.
If you do not want the control to ever get focus via keyboard, you can also set its TabStop
property to false.
If you want that the button should not have focus when you open the form, then you need to correct the TabIndex
property. The TabIndex
property has an integer as value which specifies the order in which the controls get focus when tab
key is pressed. If the control has TabIndex
set to 0 then change it to some other value.
Check the documentation for TabIndex and TabStop properties on MSDN.
Use TabStop
property of button
button1.TabStop = false;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With