问题描述
大家好,我回来了。
首先,我要感谢你给我的正规表达,它很高兴地解决了我的问题。:笨蛋:
现在,在对数组进行排序之前,我从TextBox1.Text中获取值(例如,323,1,65,7,3,999,0,)。 />
我如何禁用此控件中的空格来限制用户提供不需要的空格?我只需要数字和逗号。:confused:
谢谢
Hi guys, am back.
First i need to thank you for the "regula expression" given to me ealier, it happily solved my problem.:thumbsup:
NOW, before sorting an array I get values from TextBox1.Text like(eg. 323,1,65,7,3,999,0,).
HOW can i disable the use of spaces in this control to restrict the user from giving unwanted spaces? I need only numbers and commas.:confused:
Thanks
推荐答案
private void TextBox1_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = e.KeyChar == ' ';
}
通过将Handled设置为true,此字符不会反映在文本框中。顺便说一句 - 请为你的变量命名,而不是VS给你的默认值。 TextBox1现在对你来说似乎不会太糟糕,但是你会记得它在6个月内的用途吗?
By setting Handled to true, this character won't be reflected in the textbox. BTW - please name your variables better than the default values that VS gives you. TextBox1 won't seem too bad to you now, but will you remember what it's for in 6 months time?
this.KeyPreview = true;
e.Handled = (e.KeyChar = " ")
此外,它不使用分号来结束行。
Also, it doesn't use semicolons to end lines.
这篇关于如何在TextBox1.Text中禁用空格键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!