TextBox按键问题
各位大侠帮帮忙:
想实现捕捉TextBox中某个按键(如D),但是不显示D字母在TextBox中,又不清空之前的内容,该如何实现?
------解决方案--------------------//用KeyPress事件处理,参考如下代码
private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
{
switch (e.KeyChar)
{
case 'd ':
case 'D ':
e.KeyChar = '\0 ';
break;
}
}
------解决方案--------------------TO:又不清空之前的内容是什么意思?
这样可以不?
private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = (e.KeyChar == 'D ' || e.KeyChar == 'd ') ? true : false;
}
------解决方案--------------------//e.Handled = (e.KeyChar == 'D ' || e.KeyChar == 'd ') ? true : false;
//e.Handled = (e.KeyChar == 'D ' || e.KeyChar == 'd '); //一样
//我用的是2005....那就用楼上的
private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = char.ToUpper(e.KeyChar) == 'D ';
}