按Enter键时如何避免选择文本框值?
How to avoid selecting textbox value when press Enter?
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 select什么都不做
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;
}
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 select什么都不做
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;
}