简体   繁体   English

按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;
 }

I have this code to act ENTER Key as TAB but when I press Enter key it is selecting textbox value as in image我有这段代码可以将 ENTER 键用作 TAB,但是当我按 Enter 键时,它正在选择文本框值,如图

在此处输入图片说明

You can tell the TextBox to select nothing您可以告诉 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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当文本框值更改为事件时,自动按下输入C# - auto press enter C# when textbox value changed as event 如何避免将文本从自动完成列表插入到textBox直到按Enter键? - How to avoid insert text from autocomplete list to textBox until press Enter? 按下文本框中的Enter键时按钮触发 - Button firing when I press enter in a textbox 如何在TextBox为空时输入默认值 - How to enter a default value when a TextBox is empty 使用InputBindings时如何避免多行TextBox Enter键被吞咽? - How to avoid multiline TextBox Enter keypress is swallowed when using InputBindings? 当用户在Jquery中按文本框输入时,如何只调用一个按钮单击功能? - How to call only one button click function when user press enter from Textbox in Jquery? 等到用户在文本框中按另一种形式按Enter键并返回值 - Wait until user press enter in textbox in another form and return value 当用户在文本框中按Enter键时,执行按钮单击事件 - Perform Button click event when user press Enter key in Textbox 如何在单个输入按下的文本框上执行自动填充搜索 - How to perform searching in autofill on textbox with single enter press C#WPF-如何将文本框的Enter键绑定到方法? - C# WPF - How to Bind TextBox Enter Key Press to a Method?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM