Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tab button switches to wrong control in windows form application

I am working in windows form application using c#. I have two fields in a form "Username" and "password" and two buttons "Login" and "Cancel". On form loading cursor is placed in Username textbox which is ok.

But when I press TAB from my keyboard instead of going to Password textbox its going to Login button. How can I set this?

Also the shortcut CTRL+A to select all text is not working in text fields. Any help?

like image 819
SidraM Avatar asked Feb 01 '26 10:02

SidraM


2 Answers

Every control on WinForms has a TabIndex. This you can find in the properties of the control. You need to adjust this value to 2 in the Password textbox if you want to have the focus switch there after tab

Select your control in the designer, go into the properties:

enter image description here

and set the TabIndex property:

enter image description here

The shortcut Cntr + A will only work if you have the focus on the TextBox! Also make sure that the ShortCutsEnabled property is set to true:

enter image description here

For reference here is the original answer for the shortcut problem. It says however that:

The TextBox control does not support the CTRL+A shortcut key when the Multiline property value is true.

like image 59
Mong Zhu Avatar answered Feb 02 '26 23:02

Mong Zhu


Change the tabindex property of your password textbox 1 higher to the tabindex of your username textbox. (i.e. Username tabindex = 1, password tebaindex = 2)

like image 31
imprezzeb Avatar answered Feb 03 '26 00:02

imprezzeb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!