【发布时间】:2011-06-13 05:54:02
【问题描述】:
我有一个带有 AutoCompleteMode = suggest 的 ComboBox,并像这样处理 KeyPress 事件:
private void searchBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Return)
{
// do stuff
}
}
但是,它没有捕捉到Enter 键。由于自动完成下拉菜单完美运行,因此它可以捕获所有其他内容。
我也尝试了这里提供的建议:http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/2db0b540-756a-4a4f-9371-adbb92409806,将表单的 KeyPreview 属性设置为 true 并在表单的 KeyPress 事件处理程序中放置一个断点:
private void Form_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = false;
}
但是,即使是表单的处理程序也没有捕捉到 enter 键!
有什么建议吗?
(如果我禁用自动完成,它会捕获 Enter 键)
【问题讨论】:
标签: c# .net winforms autocomplete c#-2.0