簡體   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;
 }

我有這段代碼可以將 ENTER 鍵用作 TAB,但是當我按 Enter 鍵時,它正在選擇文本框值,如圖

在此處輸入圖片說明

您可以告訴 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM