1

Possible Duplicates:
validating textbox in windows form applications
validating textbox in windows form application

The Event not allowing Any Spaces , 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);
}
Community
  • 1
  • 1
Rangababu
  • 21
  • 1
  • 3

1 Answers1

0

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

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321