I use this function for this, I apply all controls to use Enter
to jump to the next.
Function code:
public static class Funcoes
{
/// <summary>
/// Ao pressionar ENTER no controle, ele pula para o próximo
/// </summary>
/// <param name="_ctrl">Controle (obs: todos os controles filhos, serão afetados)</param>
public static void TrocaTabPorEnter(Control _ctrl)
{
if (_ctrl.HasChildren)
{
foreach (Control _child in _ctrl.Controls)
{
if (_ctrl.HasChildren)
TrocaTabPorEnter(_child);
}
}
else
{
///Não funciona para Numeric Up Down _ctrl is Button ||
if (_ctrl is RichTextBox || _ctrl is Button || _ctrl is TextBox || _ctrl is MaskedTextBox || _ctrl is ListBox || _ctrl is CheckBox || _ctrl is DateTimePicker || _ctrl is ComboBox || _ctrl is NumericUpDown || _ctrl is TrackBar || _ctrl is RadioButton || _ctrl is TabPage)
{
TextBox tb;
if (_ctrl is TextBox)
{
tb = ((TextBox)_ctrl);
if (!tb.Multiline)
{
/// inibe a ação do Enter para evitar o comportamento de
/// Accept em alguns casos
_ctrl.KeyDown += delegate(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
e.SuppressKeyPress = true;
_ctrl.FindForm().SelectNextControl(_ctrl, !e.Shift, true, true, true);
}
};
}
else
{
tb.ScrollBars = ScrollBars.Both;
_ctrl.KeyDown += delegate(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter && e.Control)
{
e.SuppressKeyPress = true;
_ctrl.FindForm().SelectNextControl(_ctrl, !e.Shift, true, true, true);
}
};
}
}
else
{
/// inibe a ação do Enter para evitar o comportamento de
/// Accept em alguns casos
_ctrl.KeyDown += delegate(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
e.SuppressKeyPress = true;
//((Control)sender).SelectNextControl(_ctrl, !e.Shift, true, true, true);
_ctrl.FindForm().SelectNextControl(_ctrl, !e.Shift, true, true, true);
}
};
}
}
}
}
}
Call the function in the Form constructor:
public Form1()
{
InitializeComponent();
Funcoes.TrocaTabPorEnter(this);
}
ps. I removed some peculiarities of my function code, please take a test.