如何在 Windows 窗体组合框中捕获回车键 [英] How do I capture the enter key in a windows forms combobox

查看:19
本文介绍了如何在 Windows 窗体组合框中捕获回车键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在组合框处于活动状态时捕获 Windows 窗体组合框中的 Enter 键?

How do I capture the enter key in a windows forms combo box when the combobox is active?

我试过听 KeyDown 和 KeyPress,我创建了一个子类并覆盖了 ProcessDialogKey,但似乎没有任何效果.

I've tried to listen to KeyDown and KeyPress and I've created a subclass and overridden ProcessDialogKey, but nothing seems to work.

有什么想法吗?

/P

推荐答案

将 KeyPress 事件连接到这样的方法:

Hook up the KeyPress event to a method like this:

protected void myCombo_OnKeyPress(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar == 13)
    {
        MessageBox.Show("Enter pressed", "Attention");                
    }
}

我已经在使用 VS2008 的 WinForms 应用程序中对此进行了测试,并且可以正常工作.

I've tested this in a WinForms application with VS2008 and it works.

如果它不适合您,请发布您的代码.

If it isn't working for you, please post your code.

这篇关于如何在 Windows 窗体组合框中捕获回车键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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