的WinForms文本框自动完成事件 [英] WinForms Textbox Autocomplete events

查看:127
本文介绍了的WinForms文本框自动完成事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.NET文本框的形式自动完成功能。该表格​​还具有 AcceptButton CancelButton 定义。如果我试图提交的建议与输入键或关闭的下拉 Esc键,我的窗体关闭。

I have a .NET TextBox with AutoComplete feature on the form. The form has also AcceptButton and CancelButton defined. If I try to commit a suggestion with Enter key or close drop down with Esc, my form closes.

我的想法是创建我的自定义文本从 TexBox 继承和捕捉输入键和逃生键,但只有当自动完成用户界面是可见的。我怎么会知道什么时候自动完成列表是可见的?

My idea is to create my custom textbox inheriting from TexBox and capture Enter key and the Escape key, but only when the autocomplete UI is visible. How could I know when the autocomplete list is visible?

public class MyTextBox : TextBox
{
    protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
    {
        if (IsOnAutoComplete())
        {
            if (keyData == Keys.Enter || keyData == Keys.Return)
            {
                return true;
            }
        }
        return base.ProcessCmdKey(ref msg, keyData);
    }
}

换句话说,你知道我怎么可能实施 IsOnAutoComplete()的方法?有任何文本框的活动注意到这一点?

In other words, do you know how could I implement IsOnAutoComplete() method? Has the textbox any events to notice this?

任何其他的解决办法是AP preciated。先谢谢了。

Any other solution would be appreciated. Thanks in advance.

推荐答案

一个简单的解决方案,我已经使用在过去是消除了接受和取消按钮协会在文本框中有焦点。

A simple solution I have used in the past is removing the Accept and Cancel button associations when the text box has focus.

    textBox1.Enter += (o, args) =>
                                    {
                                        AcceptButton = null;
                                        CancelButton = null;
                                    };
    textBox1.Leave += (o, args) =>
                                    {
                                        AcceptButton = btnOK;
                                        CancelButton = btnCancel;
                                    };

这篇关于的WinForms文本框自动完成事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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