The AutoComplete feature has a couple of quirks that were inherited from its original designed use, the address box of Internet Explorer. This includes emitting the Enter key when you click on an item in the list. Pressing Enter in the address box of IE makes it navigate to the entered URL.
There isn't anything you can do about that, the native interface (IAutoComplete2) has very few options to configure the way it works. It pokes the keystrokes into the text box by faking Windows messages. Which is one way you can tell the difference, the actual key won't be down. Something you can check by pinvoking GetKeyState(), like this:
private void textBox1_KeyDown(object sender, KeyEventArgs e) {
if (e.KeyData == Keys.Enter && GetKeyState(Keys.Enter) < 0) {
Console.WriteLine("Really down");
}
}
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern short GetKeyState(Keys key);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…