如何避免按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; 
} 

我有这样的代码充当进入键,TAB,但是当我按下回车键则选择文本框的值作为图像如何避免按Enter键时选择文本框的值?

enter image description here

你可以告诉文本框,选择什么

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; 
} 
+0

光标焦点在文本框的值开始。它可以在文本框值的末尾? – Vampire

+0

@吸血鬼当然,编辑了样本。只要告诉它在字符串的末尾选择0个字符 –

+0

谢谢,这是工作 – Vampire