-2

I created 4 textboxes where I will key in my binary digits, one digit on one textbox. Now, I want to make sure that all the text boxes have a property MaxLength and that it must only accept digits not chars and size must accommodate a number/digit.

Jino
  • 345
  • 1
  • 2
  • 16

3 Answers3

0

You should use TextBox.MaxLength = 1 and also engage OnKeyDown event to stop users to enter any other digits except 0 or 1.

Umesh
  • 2,704
  • 19
  • 21
0

Well you can try this one for each textbox:

TextBox myTextBox = new TextBox();
myTextBox.MaxLength = 50;

And here is a similar post regarding texbox input that accepts only digits:How do I make a textbox that only accepts numbers?

Community
  • 1
  • 1
0

Set TextBox.MaxLength and use the OnKeyPress event to apply your restictions

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
    if (!char.IsDigit(e.KeyChar) )
    {
        e.Handled = true;
    }
}
bit
  • 4,407
  • 1
  • 28
  • 50