Reputation: 13395
I wanted to have textbox always focused. So I decided to add LostFocus
handler
this.textBox1.LostFocus += new System.EventHandler(delegate(object sender, System.EventArgs e)
{
this.textBox1.Focus();
});
But when I press buttons on the form and then begin to write into textbox again - it starts to add symbols before current text in textbox. For the example if I've got text in textbox abcd
and then press button on the form and start to write again 1234
I have in the textbox text 1234abcd
.
How to resolve this problem?
Upvotes: 1
Views: 248
Reputation: 6805
Just use select method like this:
void textBox1_LostFocus(object sender, EventArgs e)
{
textBox1.Focus();
textBox1.Select(textBox1.Text.Length, 0);
}
Upvotes: 1
Reputation: 1380
this.textBox1.LostFocus += new System.EventHandler(delegate(object sender, System.EventArgs e)
{
this.textBox1.Focus();
this.textBox1.AppendText("") ;
});
Upvotes: 1
Reputation: 164291
this.textBox1.Focus();
this.textBox1.Select(textBox1.Text.Length, 0)
Upvotes: 3