C# 如何避免在按Enter键时选择文本框值?
我有这个代码来充当输入键作为选项卡,但当我按下输入键时,它正在选择文本框值,如图所示C# 如何避免在按Enter键时选择文本框值?,c#,windows,enter,C#,Windows,Enter,我有这个代码来充当输入键作为选项卡,但当我按下输入键时,它正在选择文本框值,如图所示 您可以告诉文本框不选择任何内容 Control nextControl; if (e.KeyCode == Keys.Enter) { nextControl = GetNextControl(ActiveControl, !e.Shift); if (nextControl == null) { nextControl = GetNextControl(nul
您可以告诉文本框不选择任何内容
Control nextControl;
if (e.KeyCode == Keys.Enter)
{
nextControl = GetNextControl(ActiveControl, !e.Shift);
if (nextControl == null)
{
nextControl = GetNextControl(null, true);
}
nextControl.Focus();
e.SuppressKeyPress = true;
}
光标聚焦在文本框值的开头。它可能在文本框值的结尾吗?@vampile-Sure,编辑了示例。只需告诉它在字符串末尾选择0个字符
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;
}