2015-06-20 57 views
2
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

回答

1

你可以告訴文本框,選擇什麼

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

相關問題