Use Enter as Tab in Windows Forms

Recently I made a Windows Form Application with a lot of text boxes for my work.
After hours of use and testing, we found out it would be more efficient if it was possible to tab from box to box hitting ‘enter’ instead of the tabulator key. Even though you by standard can’t assign it in Visual Studio, it’s actually fairly easy to implement.

All you need to make is one event handler and assign your text boxes ‘KeyDown’ action to use the handler.

[csharp]
//Event handler to handle ENTER as TAB in TextBoxes
private void General_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
this.ProcessTabKey(true);
}
}
[/csharp]

Select your Text Boxes, go to the properties windows and select the lightning icon. Scroll down to “Key”. Under ‘KeyDown’ select your newly created event handler “General_KeyDown’.

Use Enter as Tab in Windows Forms

Group radio buttons in Windows Form

To have multiple groups of radio buttons that should not affect each other, it is necessary to group them as a GroupBox or Panel.

In Visual Studio, open your toolbox, scroll down to “Containers” and choose your box / panel. All radio buttons in this box / panel will now be interconnected.

Group radio buttons

Clear all TextBoxes

This loop function will clear all TextBoxes in your Form, wherever they are placed.
Comes in handy when creating a “Clear fields” button

[csharp]
private void button1_Click(object sender, EventArgs e)
{
RecursiveClearTextBoxes(this.Controls);
}

private void RecursiveClearTextBoxes(Control.ControlCollection cc)
{
foreach (Control ctrl in cc)
{
TextBox tb = ctrl as TextBox;
if (tb != null)
tb.Clear();
else
RecursiveClearTextBoxes(ctrl.Controls);
}
}
[/csharp]