Reputation: 27
I'm new to c# and I tried making a simple program. After I click the button, the values won't update with their actual value, so I have to click twice to make them actually work. Here's my code:
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private static int p;
private static int money;
public Form1()
{
InitializeComponent();
p = 0;
money = 100;
}
private void button1_Click(object sender, EventArgs e)
{
m.Text = money.ToString();
ex.Text = p.ToString();
if (checkBox1.Checked && checkBox2.Checked)
{
MessageBox.Show("You cannot select both.", "Nope");
}
else if (checkBox1.Checked)
{
p += 2;
}
else if (checkBox2.Checked)
{
money -= 50;
p += 10;
}
else
{
return;
}
}
}
}
Upvotes: 0
Views: 110
Reputation: 43300
You need to update the text after updating the value
if (checkBox1.Checked & checkBox2.Checked)
{
MessageBox.Show("You cannot select both.", "Nope");
}
....
m.Text = money.ToString();
ex.Text = p.ToString();
Upvotes: 5