在Windows窗体应用程序验证文本框 [英] validating textbox in windows form application
问题描述
如何验证文本框,而不允许在窗户的空间使用C#.NET
在我的项目。我可以验证文本框窗体应用程序,而不允许在这两个东西的空间....
。 ............
1.only不允许有空格
2.after输入一个或两个字符的文本框接受空格...........
how to validate the textbox without allowing spaces in windows form application using C#.net in my project .i can validate the text box ,without allowing spaces.... in this two things ............. 1.only spaces are not allowed 2.after entering one or two characters textbox accept spaces...........
推荐答案
您可以通过处理进入的文本框
空间限制用户在的KeyPress
事件
You can restrict the user from entering space in the TextBox
by handling the KeyPress
event
void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = (e.KeyChar == (char)Keys.Space);
}
修改
在空间的情况下正进入一个或两个角色,那么你应该使用
In case space is allowed after entering a character or two , then you should be using
textbox1.Text.TrimStart允许()
这篇关于在Windows窗体应用程序验证文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!