[英]c# values don't work correctly
I'm new to c# and I tried making a simple program. 我是C#的新手,我尝试制作一个简单的程序。 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;
}
}
}
}
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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.