文本框自动完成和默认按钮 [英] TextBox autocomplete and default buttons
本文介绍了文本框自动完成和默认按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表单上自动完成功能的.NET文本框。该表格还的AcceptButton和CancelButton定义。如果我试图提交一个建议用回车键或关闭下拉Esc键,我的窗体关闭。
我怎样才能prevent这种行为?
I have a .NET TextBox with AutoComplete feature on the form. The form has also AcceptButton and CancelButton defined. If I try to commit a suggestion with Enter key or close drop down with Esc, my form closes. How can I prevent this behavior?
推荐答案
简单的方法就是当你在自动完成文本框删除的AcceptButton 和 CancelButton 属性:
Simple way is to remove AcceptButton and CancelButton properties while you are in auto-complete textbox:
public Form1()
{
InitializeComponent();
txtAuto.Enter +=txtAuto_Enter;
txtAuto.Leave +=txtAuto_Leave;
}
private void txtAC_Enter(object sender, EventArgs e)
{
AcceptButton = null;
CancelButton = null;
}
private void txtAC_Leave(object sender, EventArgs e)
{
AcceptButton = btnOk;
CancelButton = btnCancel;
}
这篇关于文本框自动完成和默认按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文