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

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

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/

相关文章:

c# - 获取目录时出现 System.UnauthorizedAccessException

JSON 结合保持文件夹结构的 gulp 任务 - 跨平台

jquery - Bootstrap 按钮按键不适用于 'Enter' 键

c# - 使用键盘选择项目时组合框崩溃

c# - ASP .NET - 替换和页面输出( donut )缓存 - 如何将自定义参数传递给 HttpResponseSubstitutionCallback 委托(delegate)

c# - 服务器/客户端。客户端使用大量内存

windows - 设置代理服务器的步骤

windows - 无法再从 Windows SDK 使用 umdh

android - Xamarin Android EditText 回车键

java - 如何检查扫描仪中是否按下了 Enter 键?