this.textBox1.Enter += new System.EventHandler(this.textBox1_Enter);
(...)
int test = 0;
private void textBox1_Enter(object sender, EventArgs e)
{
///
/// update completion from db
///
++test;
Log("got focus " + test);
}
我从我的日志语句中得到这个结果:
[03/08/2013 13:56:40]:获得焦点 1
[03/08/2013 13:56:40]:获得焦点 2
为什么每次单击文本框时都会调用此函数两次?
我已经检查过了:我只有一个对这个函数的引用。
编辑:
真正的功能看起来更像
private void textBox1_Enter(object sender, EventArgs e)
{
// update completion
List<string> allValues = getValuesFromDb();
myAutoComplete = new AutoCompleteStringCollection();
myAutoComplete.AddRange(allValues.ToArray());
textBox1.AutoCompleteCustomSource = myAutoComplete; /// this line calls enter event again
++test;
Log("got focus " + test);
}