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 を取得
テキスト ボックスをクリックするたびに、この関数が 2 回呼び出されるのはなぜですか?
確認済み: この関数への参照は 1 つしかありません。
編集:
実際の関数はそのように見えます
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);
}