自动完成组合框onkey preSS事件吃掉Enter键 [英] Autocomplete on Combobox onkeypress event eats up the Enter key
问题描述
我有一个 AutoCompleteMode =组合框提示
和处理关键preSS事件像这样:
I have a ComboBox with AutoCompleteMode = suggest
and handle the KeyPress event like so:
private void searchBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Return)
{
// do stuff
}
}
不过,这并不赶上输入
键。它捕捉一切以来的自动完成下拉完美的作品。
However, it does not catch the Enter
key. It catches everything else since the autocomplete dropdown works perfectly.
我也试过这里提供的建议:<一href="http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/2db0b540-756a-4a4f-9371-adbb92409806" rel="nofollow">http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/2db0b540-756a-4a4f-9371-adbb92409806,设置窗体的键preVIEW
属性为true,把一个断点形式的关键preSS事件处理程序:
I also tried the suggestion offered here : http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/2db0b540-756a-4a4f-9371-adbb92409806, set the form's KeyPreview
property to true and put a breakpoint in the form's KeyPress event handler:
private void Form_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = false;
}
然而,即使表单的处理程序没有赶上回车键!
However, even the form's handler was not catching the enter key!
有什么建议?
(如果我禁用了自动完成,它捕获回车键)
(If I disable the autocomplete, it catches the Enter key)
推荐答案
<一个href="http://stackoverflow.com/questions/1367700/whats-the-difference-between-keydown-and-key$p$pss-in-net">Difference KeyDown和关键preSS 之间
在你的情况,你可以做的最好的是使用KeyDown事件。
In your case the best you may do is use KeyDown event.
void SearchBox_KeyDown(object sender, KeyEventArgs e)
{
if(e.KeyCode == Keys.Enter)
{
// Do stuff
}
}
有关重点preSS事件另一个有趣的事情是:它甚至渔获物。如果组合框有没有项目Enter键与autocompete! :-)
Another interesting thing about KeyPress event is: it even catches Enter key with autocompete on if the combobox has no items! :-)
这篇关于自动完成组合框onkey preSS事件吃掉Enter键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!