作者:shadowsuyan3 | 来源:互联网 | 2023-05-17 09:11
Iamtryingtomakeatext-boxwhichwillonlyacceptnumbers,whitespacesandplussign.我正在尝试制作一个
I am trying to make a text-box
which will only accept numbers, white spaces and plus sign.
我正在尝试制作一个只接受数字,空格和加号的文本框。
Currently I have done something like this in KeyPressEvent
of the textbox
目前我在文本框的KeyPressEvent中做了类似的事情
if (!char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar) &&!char.IsWhiteSpace(e.KeyChar))
{
e.Handled = true;
}
I want to accept the +
sign as well
我也想接受+号
Update
I did handle the !char.IsSymbol(e.KeyChar)
but it will accept the =
sign as well with the +
我确实处理了!char.IsSymbol(e.KeyChar),但它也会接受=符号和+
Any help!!!
Thanks
3 个解决方案