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

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

问题描述

当组合框处于活动状态时,如何在Windows窗体组合框中捕获回车键?

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

我试图监听KeyDown和KeyPress,

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



我在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天全站免登陆