每次按下按钮而不必每次都输入新值时,如何更新计算?
private void buttonNextMonth_Click(object sender, EventArgs e)
{
int month = 0;
decimal monthlyRate, annualRate, monthlySavings, balance, initialSavings;
annualRate = decimal.Parse(textBox2.Text);
initialSavings = decimal.Parse(textBox1.Text);
monthlyRate = annualRate / 12;
monthlySavings = initialSavings * 1;
balance = (monthlyRate * monthlySavings) + initialSavings;
month++;
textBox4.Text = balance.ToString();
textBox3.Text = month.ToString();
答案 0 :(得分:0)
将您的计数器置于点击事件之外,以便每次点击按钮时都不会启动计数器
喜欢这个
int month = 0;
private void buttonNextMonth_Click(object sender, EventArgs e)
{
decimal monthlyRate, annualRate, monthlySavings, balance, initialSavings;
annualRate = decimal.Parse(textBox2.Text);
initialSavings = decimal.Parse(textBox1.Text);
monthlyRate = annualRate / 12;
monthlySavings = initialSavings * 1;
balance = (monthlyRate * monthlySavings) + initialSavings;
month++;
textBox4.Text = balance.ToString();
textBox3.Text = month.ToString();