I create a calculator. But here I met such a problem: I click on the buttons with numbers and at the same time the number (one) is highlighted in the TextBox, but when I click on another button, the old one is deleted and a new one (one) is displayed instead. For the first time I encounter such a problem. What's the matter???

Here is the code:

private void button25_Click(object sender, EventArgs e) { textBox1.Text = "1"; } private void button24_Click(object sender, EventArgs e) { textBox1.Text = "2"; } 
  • 2
    button24 button25 is strong (the code is the same) - rasmisha

1 answer 1

You replace the contents of TextBox

 private void button25_Click(object sender, EventArgs e) { TextBox1.Text = TextBox1.Text + "1"; } private void button24_Click(object sender, EventArgs e) { TextBox1.Text = TextBox1.Text + "2"; } 
  • 2
    Not & but + . - AlexeyM
  • one
    Not familiar with this with your BASIC-with-braces, but AlexeyM is right, and concatenation will happen, not addition. String same! - karmadro4
  • one
    @ niki-timofe How did you even think of using '&' here? Please tell us the course of your thoughts, very interesting. - Costantino Rupert
  • one
    @ niki-timofe - What you said about the addition operation applicable to String types in VB is [not true.] [1] In VB "abc" + "def" -> "abcdef". Well, this never justifies the fact of splitting the VB code when answering a question about C# :) - (Offtopic) Using operator & for strict concatenation of lines is, by the way, a very strange language solution. Personally, I don’t really understand why operator + was assigned so complex logic that I had to introduce an additional strict operator to concatenate lines. [1]: msdn.microsoft.com/library/te2585xw - Costantino Rupert 2:55 pm
  • one
    @ Kotik_hochet_kusat, this is not an introduction, but a return to the traditional concatenation operator for BASIC. - karmadro4