开发者

TextBox GotFocus event not responding

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜