日期:2014-05-20  浏览次数:20814 次

敬望指教:关于textBox的一个问题。
某个textBox获得焦点后,可通过键盘输入数据。当键入Esc键时,系统会发出一声峰鸣(错误提示音)。小弟定义了KeyPress事件后,想关闭键入Esc键时系统发出的峰鸣音,如何才能实现呢?

------解决方案--------------------
private void text1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(Convert.ToInt32(e.KeyChar) == 27)
{
//按下ESC键时处理...
}
}

其实没有必要这样做吧。。。
------解决方案--------------------
借上面的:
if(Convert.ToInt32(e.KeyChar) == 27)
{
e.Handled = true ;
}
------解决方案--------------------
借上面的:
if(Convert.ToInt32(e.KeyChar) == 27)
{
e.Handled = true ;
}


这个应该能实现吧。
------解决方案--------------------
//除了
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = (e.KeyChar == (char)27) || (e.KeyChar == (char)13);
}

//还有种变态的方法是这样
textBox1.AutoCompleteCustomSource.Add( "\01 ");
textBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;