Control nextControl;
if (e.KeyCode == Keys.Enter)
{
    nextControl = GetNextControl(ActiveControl, !e.Shift);
    if (nextControl == null)
    {
        nextControl = GetNextControl(null, true);
    }
    nextControl.Focus();
    e.SuppressKeyPress = true;
 }

我有此代码将ENTER键用作TAB键,但是当我按Enter键时,它正在选择文本框中的值,如图所示

最佳答案

您可以告诉TextBox不选择任何内容

Control nextControl;

if (e.KeyCode == Keys.Enter)
{
    nextControl = GetNextControl(ActiveControl, !e.Shift);
    if (nextControl == null)
    {
        nextControl = GetNextControl(null, true);
    }
    nextControl.Focus();

    TextBox box = nextControl as TextBox;
    if (box != null)
        box.Select(box.Text.Length, 0);

    e.SuppressKeyPress = true;
}

08-26 15:13