gpt4 book ai didi

c# - 按Enter键时如何避免选择文本框值?

转载 作者:可可西里 更新时间:2023-11-01 10:35:20 26 4
gpt4 key购买 nike

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 键时,它正在选择图像中的文本框值

enter image description here

最佳答案

您可以告诉 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;
}

关于c# - 按Enter键时如何避免选择文本框值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30950454/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com