How do I capture the enter key in a windows forms combobox

前端 未结 7 592
盖世英雄少女心
盖世英雄少女心 2021-01-07 21:33

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

I\'ve tried to listen to KeyDown and KeyPress and I\'ve created a subclass a

7条回答
  •  庸人自扰
    2021-01-07 21:52

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

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

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

提交回复
热议问题