I am doing exercises and I come up with a problem I will be happy if someone help me and enlighten.
button1 writes 1 into the texbox1 but I want to limit the number of characters that one person can write and in this example I want to limit at 4 character. Which means one can enter no more than 4 character.
PROBLEM IS: when I click on the textbox1 properties and change the MaxLength property it works if I enter characters via the keyboard but when set the textbox1 to readonly, then it does NOT work. I can enter as many 1 as I can when I click the button1.
WHAT CAN I DO? I want to make the textbox1 readonly and want to write max 4 character when I press button1.
And QUESTION 2 is : I want to make button1 press when I press the enter key on my keyboard. Thanks in advance.
here is my code
namespace formlar
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//textBox1.Text += textBox1.Text = "1";
textBox1.Text += "1";
}
}
}

If you look at the documentation it says
MaxLength
So if you want to restrict in the code you will have to add that check and then stop the addition part.
Set the
AcceptButtonproperty of the current form to theButtonyou want