简体   繁体   English

TextBox GotFocus事件未响应

[英]TextBox GotFocus event not responding

Very simple: 很简单:

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

This does not appear to be doing anything. 这似乎没有做任何事情。 my textBox is called textBox1. 我的textBox称为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. GotFocus事件对设计器是隐藏的,因此您必须自己进行操作。

As Hans pointed out, GotFocus is basically replaced by the Enter event, and you should use that instead: 正如Hans所指出的,GotFocus基本上由Enter事件代替,您应该使用它代替:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM