开发者

validating textbox in windows form applications [duplicate]

This question already has answers here: Closed 11 years ago.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜