我一直在尝试通过if语句来启用按钮,但是我不确定在哪里出错。
private void btnPayment_Click(object sender, EventArgs e)
{
double MonthlyPayment = 0;
double interest = cboInterest.SelectedIndex;
double term = cboTerm.SelectedIndex;
double principal = Double.Parse(txtPrincipal.Text);
double expN = Math.Pow(1+interest, term*12)-1;
MonthlyPayment = principal * (((interest / 12) * expN) / (expN - 1));
string strMP = MonthlyPayment.ToString();
string intrst = interest.ToString();
string trm = term.ToString();
string princ = principal.ToString();
if (principal >= 0)
{
this.btnPayment.Enabled = true;
}
lblResult.Text = "The monthly payment for a loan of $" + princ + " at " + intrst + "% for " + trm + " years is $" + strMP;
}
}
}
这永远行不通,您正在尝试通过已禁用按钮的click事件启用按钮吗?我能看到的至少是Atleast。
我认为您需要检查txtPrincipal.Text离开事件。即,当用户离开此文本框时,应具有检查值(如果存在)和大于0的数字的功能,如果满足这些条件,则启用按钮。