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.
Asked
Active
Viewed 70 times
-2
-
2What have `YOU` tried sofar? – User999999 Mar 18 '14 at 09:04
-
Is it a Web forms, Winforms, WPF, MVC........ application? – Seany84 Mar 18 '14 at 09:05
-
1Hi @nutty, C# tag alone is not sufficient for a question like this. You should add the tag that specifies your application type like WinForms or WPF to the question so others can understand your context better. – Şafak Gür Mar 18 '14 at 09:20
3 Answers
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