只有第一个 if 语句触发
Only first if statement firing
所以我正在研究一个 3 位数的计算器,但出于某种原因,我只能让它相加,我不知道为什么。我觉得它会被指出给我,我会觉得自己很愚蠢。
private void CalcCalcBtn_Click(object sender, EventArgs e)
{
double num1 = double.Parse(calc1Txt.Text);
double num2 = double.Parse(calc2Txt.Text);
double num3 = double.Parse(calc3Txt.Text);
{
if(calcAddBtn.Enabled == true)
{
double output = (num1 + num2 + num3);
calcOpLbl.Text = output.ToString("0.00");
}
else if(calcSubBtn.Enabled == true)
{
double output = (num1 - num2 - num3);
calcOpLbl.Text = output.ToString("0.00");
}
else if(calcMutBtn.Enabled == true)
{
double output = (num1 * num2 * num3);
calcOpLbl.Text = output.ToString("0.00");
}
else if(calcDivBtn.Enabled == true)
{
double output = (num1 / num2 / num3);
calcOpLbl.Text = output.ToString("0.00");
}
}
}
Enabled
表示 "is it possible for the user to click this button",而不是 "is this the button that the user just clicked"。由于所有这四个按钮始终处于启用状态,因此第一个按钮始终为真,else
表示它不会费心查看其余按钮。
所以我正在研究一个 3 位数的计算器,但出于某种原因,我只能让它相加,我不知道为什么。我觉得它会被指出给我,我会觉得自己很愚蠢。
private void CalcCalcBtn_Click(object sender, EventArgs e)
{
double num1 = double.Parse(calc1Txt.Text);
double num2 = double.Parse(calc2Txt.Text);
double num3 = double.Parse(calc3Txt.Text);
{
if(calcAddBtn.Enabled == true)
{
double output = (num1 + num2 + num3);
calcOpLbl.Text = output.ToString("0.00");
}
else if(calcSubBtn.Enabled == true)
{
double output = (num1 - num2 - num3);
calcOpLbl.Text = output.ToString("0.00");
}
else if(calcMutBtn.Enabled == true)
{
double output = (num1 * num2 * num3);
calcOpLbl.Text = output.ToString("0.00");
}
else if(calcDivBtn.Enabled == true)
{
double output = (num1 / num2 / num3);
calcOpLbl.Text = output.ToString("0.00");
}
}
}
Enabled
表示 "is it possible for the user to click this button",而不是 "is this the button that the user just clicked"。由于所有这四个按钮始终处于启用状态,因此第一个按钮始终为真,else
表示它不会费心查看其余按钮。