I'm new to programming and I have a problem. I have two buttons and a textbox. When I press the button, a number will show on the textbox, but when I press the second button the number in the textbox overwrites it and replaces it instead of adding to it in the textbox. How do I fix this? I want the values to add instead of replacing it.
public partial class Form1 : Form
{
int value1 = 0;
int value2 = 0;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
value1++;
textBox1.Text = value1.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
value2 += 2;
textBox1.Text = value2.ToString();
}
}
}
textBox1.Text = (int.Parse(textBox1.Text) + value2).ToString();