validating textbox in windows form applications [duplicate]
Possible Duplicates:
validating textbox in windows form applications validating textbox in windows form application
The Event not allowing Any Spac开发者_C百科es , But i want Avoid start one or two or three Spaces in text box in windows form application using C#.net
void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = (e.KeyChar == (char)Keys.Space);
}
Even the edited question is really hard to make sense of. So I'm going to guess that you meant to say: "I want to avoid a textbox starting with 1,2 or 3 spaces"
In the TextChanged event use String.Trim, or use Replace(" ",string.empty), or if its critical for a max of 3 spaces use a for loop and only remove the spaces with String.Substring
精彩评论