选择从自动完成建议列表中的项目引发的KeyDown事件与ENTER键 [英] Selecting an item from AutoComplete suggestion list raises KeyDown-event with ENTER key

查看:120
本文介绍了选择从自动完成建议列表中的项目引发的KeyDown事件与ENTER键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在的WinForms我有AutoCompleteMode一个文本框设置为SuggestAppend和AutoCompleteCustomSource集。当用户输入一些字母显示建议列表。如果这个列表中的项目是通过用鼠标点击它选中,是上调ENTER键的形式包含文本框中的KeyDown事件。

In Winforms I have a textbox with AutoCompleteMode set to SuggestAppend and a AutoCompleteCustomSource set. When the user types some letters the suggestion list is shown. If an item of this list is selected by clicking it with the mouse, the KeyDown-event of the form containing the textbox is raised for the ENTER key.

用鼠标选择一个建议的项目时是否有可能以不引发此事件?

Is there any possibility to NOT raise this event when selecting a suggested item with the mouse?

推荐答案

自动完成功能有几个从原设计的使用,互联网浏览器的地址栏中继承的怪癖。这包括发光当你点击列表中的一个项目,Enter键。 pressing在IE的地址栏中输入使得导航到输入的URL。

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.

有没有什么可以做这件事,本机接口(IAutoComplete2)有极少数的选项来配置它的工作方式。它通过伪造Windows消息捅击键到文本框中。这是你能分辨出来的一种方式,实际的密钥也不会下降。有些事情,你可以通过pinvoking函数GetKeyState(),这样的检查:

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);

这篇关于选择从自动完成建议列表中的项目引发的KeyDown事件与ENTER键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆