• <small id='Ds3ZG'></small><noframes id='Ds3ZG'>

    1. <legend id='Ds3ZG'><style id='Ds3ZG'><dir id='Ds3ZG'><q id='Ds3ZG'></q></dir></style></legend>
        <bdo id='Ds3ZG'></bdo><ul id='Ds3ZG'></ul>
      <i id='Ds3ZG'><tr id='Ds3ZG'><dt id='Ds3ZG'><q id='Ds3ZG'><span id='Ds3ZG'><b id='Ds3ZG'><form id='Ds3ZG'><ins id='Ds3ZG'></ins><ul id='Ds3ZG'></ul><sub id='Ds3ZG'></sub></form><legend id='Ds3ZG'></legend><bdo id='Ds3ZG'><pre id='Ds3ZG'><center id='Ds3ZG'></center></pre></bdo></b><th id='Ds3ZG'></th></span></q></dt></tr></i><div id='Ds3ZG'><tfoot id='Ds3ZG'></tfoot><dl id='Ds3ZG'><fieldset id='Ds3ZG'></fieldset></dl></div>

    2. <tfoot id='Ds3ZG'></tfoot>

      1. 从自动完成建议列表中选择一个项目会引发带有 ENTER 键的 KeyDown-event

        时间:2023-06-09
          <tbody id='dLidn'></tbody>

        <i id='dLidn'><tr id='dLidn'><dt id='dLidn'><q id='dLidn'><span id='dLidn'><b id='dLidn'><form id='dLidn'><ins id='dLidn'></ins><ul id='dLidn'></ul><sub id='dLidn'></sub></form><legend id='dLidn'></legend><bdo id='dLidn'><pre id='dLidn'><center id='dLidn'></center></pre></bdo></b><th id='dLidn'></th></span></q></dt></tr></i><div id='dLidn'><tfoot id='dLidn'></tfoot><dl id='dLidn'><fieldset id='dLidn'></fieldset></dl></div>
        <tfoot id='dLidn'></tfoot>
      2. <legend id='dLidn'><style id='dLidn'><dir id='dLidn'><q id='dLidn'></q></dir></style></legend>

          <bdo id='dLidn'></bdo><ul id='dLidn'></ul>

                  <small id='dLidn'></small><noframes id='dLidn'>

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

                  问题描述

                  在 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?

                  推荐答案

                  自动完成功能有几个怪癖,这些怪癖继承自其最初的设计用途,即 Internet Explorer 的地址框.这包括在您单击列表中的项目时发出 Enter 键.在 IE 的地址框中按 Enter 键会导航到输入的 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 消息将击键插入文本框.这是您可以区分的一种方法,实际的密钥不会被关闭.您可以通过调用 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);
                  

                  这篇关于从自动完成建议列表中选择一个项目会引发带有 ENTER 键的 KeyDown-event的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:C# 在禁用的文本框(表单)上显示工具提示 下一篇:asp.net 验证文本框 - 至少一个文本框必须有数据

                  相关文章

                  <i id='Hxbji'><tr id='Hxbji'><dt id='Hxbji'><q id='Hxbji'><span id='Hxbji'><b id='Hxbji'><form id='Hxbji'><ins id='Hxbji'></ins><ul id='Hxbji'></ul><sub id='Hxbji'></sub></form><legend id='Hxbji'></legend><bdo id='Hxbji'><pre id='Hxbji'><center id='Hxbji'></center></pre></bdo></b><th id='Hxbji'></th></span></q></dt></tr></i><div id='Hxbji'><tfoot id='Hxbji'></tfoot><dl id='Hxbji'><fieldset id='Hxbji'></fieldset></dl></div>
                  <tfoot id='Hxbji'></tfoot>

                      <bdo id='Hxbji'></bdo><ul id='Hxbji'></ul>

                    <small id='Hxbji'></small><noframes id='Hxbji'>

                  1. <legend id='Hxbji'><style id='Hxbji'><dir id='Hxbji'><q id='Hxbji'></q></dir></style></legend>