1

我想让文本框始终聚焦。所以我决定添加LostFocus处理程序

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

但是当我按下表单上的按钮然后再次开始写入文本框时 - 它开始在文本框中的当前文本之前添加符号。例如,如果我在文本框中有文本abcd,然后按表单上的按钮并再次开始写作,1234我在文本框中有文本1234abcd

如何解决这个问题?

4

3 回答 3

3
this.textBox1.Focus();
this.textBox1.Select(textBox1.Text.Length, 0)
于 2012-09-15T17:54:52.397 回答
1
this.textBox1.LostFocus += new System.EventHandler(delegate(object sender, System.EventArgs e) 
                                                   {
                                                      this.textBox1.Focus();
                                                       this.textBox1.AppendText("") ;
                                                   });
于 2012-09-15T17:58:12.783 回答
1

只需使用这样的选择方法:

    void textBox1_LostFocus(object sender, EventArgs e)
    {
        textBox1.Focus();
        textBox1.Select(textBox1.Text.Length, 0);
    }
于 2012-09-15T17:59:18.430 回答