日期:2014-05-18 浏览次数:21416 次
private void txtArrears_KeyPress(object sender, KeyPressEventArgs e) { if (((e.KeyChar >= '0') && (e.KeyChar <= '9')) || (e.KeyChar == '.') || (e.KeyChar == (char)8) ) { e.Handled = false; } else { e.Handled = true ; } }
private void txtArrears_KeyPress(object sender, KeyPressEventArgs e) { if ((Control.ModifierKeys & Keys.Control) == Keys.Control) return; e.Handled = !(((e.KeyChar >= '0') && (e.KeyChar <= '9')) || (e.KeyChar == '.') || (e.KeyChar == (char)8)); }
------解决方案--------------------
那个判断还可以简化为:
e.Handled = "0123456789.\x8".IndexOf(e.KeyChar) < 0;
------解决方案--------------------
onkeypress事件,写一小段JS代码即可
------解决方案--------------------
友情提示:鼠标的动作也要考虑,比如右键的粘帖,直接拖过来的数据等等~~~~~