文本框文字问题 [英] a problem of text box text
本文介绍了文本框文字问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我以C#格式放置一个文本框.在该文本框中,我只想输入数字.如果我们按其他按钮,则不会在文本框中打印.
In c# form i put a text box. In that text box, i want only type numbers. If we press other buttons, it don''t print in the text box. Do anybody knows a method?
推荐答案
如何使用 NumericUpDown 控件代替?
或者,您也可以查看以下内容:简单数字文本框 [
How about using the NumericUpDown control instead?
Or you can check this out: Simple Numeric TextBox[^]
我建议您忘记更改行为TextBox
并使用NumericUpDown
http://msdn.microsoft.com/en-us/library/system. windows.forms.numericupdown.aspx [ ^ ]
如果由于某些原因绝对需要TextBox
,则可以处理 KeyPress [ ^ ]事件
I would suggest you forget about changing the behavoir of theTextBox
and useNumericUpDown
http://msdn.microsoft.com/en-us/library/system.windows.forms.numericupdown.aspx[^]
If you absolutely need aTextBox
for some reason, then you can handle the KeyPress[^] event
private void MyTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = !char.IsDigit(e.KeyChar);
}
private void tbxHeightBackImage_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = !char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar);
}
这篇关于文本框文字问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文