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 t开发者_StackOverflow社区o 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;
精彩评论