2012-09-15 51 views
1

我想讓文本框始終保持專注。所以我決定加入LostFocus處理移動到文本框中文本的末尾

this.textBox1.LostFocus += new System.EventHandler(delegate(object sender, System.EventArgs e) 
                { 
                 this.textBox1.Focus(); 
                }); 

但是,當我按在窗體上按鈕,然後開始再次寫入文本 - 它開始在文本框中當前文本之前添加符號。例如,如果我在文本框中輸入了文本abcd,然後按下表格上的按鈕並開始再次寫入1234我在文本框中輸入文本1234abcd

如何解決此問題?

回答

1
this.textBox1.LostFocus += new System.EventHandler(delegate(object sender, System.EventArgs e) 
                { 
                 this.textBox1.Focus(); 
                 this.textBox1.AppendText("") ; 
                }); 
+1

嘗試,這可能爲你工作 –

+1

是啊。它的話是正確的。 – lapots

3
this.textBox1.Focus(); 
this.textBox1.Select(textBox1.Text.Length, 0) 
1

只需使用選擇的方法是這樣的:

void textBox1_LostFocus(object sender, EventArgs e) 
    { 
     textBox1.Focus(); 
     textBox1.Select(textBox1.Text.Length, 0); 
    } 
相關問題