I am simulating an electronic urn in C #. To limit data entry, I decided to create a "keyboard" from 0 to 9, for the insertion of the votes. However, I'm having trouble limiting the amount of characters in the textbox, even setting the maximum size to 2 characters, for example, when using the buttons the maximum size of the textbox is ignored by the buttons, which add text infinitely, but not when use the computer keyboard. Is there any way to resolve this?
Here is an example of the code I'm using and a print of how my form is currently:
private void btnUm_Click(object sender, EventArgs e)
{
txtNum.Text += "1";
}
private void btnDois_Click(object sender, EventArgs e)
{
txtNum.Text+="2";
}
private void btnTres_Click(object sender, EventArgs e)
{
txtNum.Text += "3";
}
private void btnQuatro_Click(object sender, EventArgs e)
{
txtNum.Text += "4";
}
private void btnCinco_Click(object sender, EventArgs e)
{
txtNum.Text += "5";
}
private void btnSeis_Click(object sender, EventArgs e)
{
txtNum.Text += "6";
}
private void btnSete_Click(object sender, EventArgs e)
{
txtNum.Text += "7";
}
private void btnOito_Click(object sender, EventArgs e)
{
txtNum.Text += "8";
}
private void btnNove_Click(object sender, EventArgs e)
{
txtNum.Text += "9";
}
private void btnZero_Click(object sender, EventArgs e)
{
txtNum.Text += "0";
}