I've several textboxes. I would like to make the Enter button act as Tab. So that when I will be in one textbox, pressing Enter will move me to the next one. Could you please tell me how to implement this approach without adding any code inside textbox class (no override and so on if possible)?
Map [Enter] key to work like the [Tab] key This caputures both Enter and Shift + Enter .
If the field you've selected has a dropdown list then CLICKING ON IT ONCE will bring the list down but not place the cursor in the field. Selecting the field a second time will place the cursor in the field. Once the cursor is actually visible in the field you will find that the TAB key works as you expect.
Here is the code that I usually use. It must be on KeyDown event.
if (e.KeyData == Keys.Enter) { e.SuppressKeyPress = true; SelectNextControl(ActiveControl, true, true, true, true); }
UPDATE
Other way is sending "TAB" key! And overriding the method make it so easier :)
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if (keyData == (Keys.Enter)) { SendKeys.Send("{TAB}"); } return base.ProcessCmdKey(ref msg, keyData); }
You can write on the keyDown of any control:
if (e.KeyCode == Keys.Enter) { if (this.GetNextControl(ActiveControl, true) != null) { e.Handled = true; this.GetNextControl(ActiveControl, true).Focus(); } }
GetNextControl doesn't work on Vista.
To make it work with Vista you will need to use the code below to replace the this.GetNextControl...:
System.Windows.Forms.SendKeys.Send("{TAB}");
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