0

我是 c# 的新手,我尝试制作一个简单的程序。单击按钮后,值不会更新为实际值,因此我必须单击两次才能使它们真正起作用。这是我的代码:

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;
            }
        }
    }
}
4

1 回答 1

5

更新值后需要更新文本

if (checkBox1.Checked & checkBox2.Checked)
{
    MessageBox.Show("You cannot select both.", "Nope");
}
....

 m.Text = money.ToString();
 ex.Text = p.ToString();
于 2013-09-13T14:54:27.027 回答