hi
u can limit textbox max length to 4, then use keypress event to validate entry:

private void [textbox]_keypress(object sender,keypressventArgs e)
{
   if((!Char.IsControl(e.char))&&(!Char.Isdigit(e.char)))
        e.handled = true;
}

then use keyup event to catch enter pressed to add controls

private void [textbox]_keyup(object snder, keyeventargs e)
{
  if (e.KeyCode == Keys.Enter)
            this.Controls.Add(label);
}

Edited 5 Years Ago by Lovelake: Added [code] tags.

You can limit textbox's maximum length by settings its attribute length/max length to 4 in the Properties panel.

As jugosoft mentioned set the max length property of the textbox to 4. You can do that using the properties panel or in the code as shown below.

private void Form1_Load(object sender, EventArgs e)
        {
            textBox1.MaxLength = 4;
        }

I want help....restrict to user enter only 10 number in textbox if user not enter 10 number curser do not go to another control........reply soon

I want help....restrict to user enter only 10 number in textbox if user not enter 10 number curser do not go to another control using c#........reply soon

This question has already been answered. Start a new discussion instead.