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

前端 未结 7 602
盖世英雄少女心
盖世英雄少女心 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:57

    Try this:

    protected override bool ProcessCmdKey(ref Message msg, Keys k)
    {
        if (k == Keys.Enter || k == Keys.Return)
        {
            this.Text = null;
            return true;
        }
    
        return base.ProcessCmdKey(ref msg, k);
    }
    

提交回复
热议问题