0

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 by Lovelake: Added [code] tags.

5
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by crishlay
0

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

0

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;
        }
0

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

0

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.
Be sure to adhere to our posting rules.