开发者

TextBox GotFocus event not responding

开发者 https://www.devze.com 2023-03-30 13:45 出处:网络
Very simple: private void textBo开发者_开发技巧x1_GotFocus(object sender, EventArgs e) { this.textBox1.Text = \"AAA\";

Very simple:

private void textBo开发者_开发技巧x1_GotFocus(object sender, EventArgs e)
{
  this.textBox1.Text = "AAA";
}

This does not appear to be doing anything. my textBox is called textBox1. No error, but it is not doing what I want.

Any idea?


In your form's constructor, make sure you have this:

this.textBox1.GotFocus += new EventHandler(textBox1_GotFocus);

The GotFocus event is hidden from the designer, so you have to do it yourself.

As Hans pointed out, GotFocus is basically replaced by the Enter event, and you should use that instead:

private void textBox1_Enter(object sender, EventArgs e)
{
  this.textBox1.Text = "AAA";
}
0

精彩评论

暂无评论...
验证码 换一张
取 消