【发布时间】:2019-11-07 21:27:43
【问题描述】:
我必须为班级创建一个程序。我的应用程序需要有 OilLubeCharges()、FlushCharges()、MiscCharges()、OtherCharges()、TaxCharges()、TotalCharges() 的值返回方法。
它需要有ClearOilLube()、ClearFlushes()、ClearMisc()、ClearOther()、ClearFees()的void方法。
目前我的代码没有语法错误,但是当我编译它时它不会计算任何东西。计算、清除和退出按钮也不起作用。任何有关为什么会出现这些问题的帮助将不胜感激。下面是我的代码。
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void CalcButton_Click(object sender, EventArgs e)
{
OilLubeCharges();
FlushCharges();
MiscCharges();
OtherCharges();
TaxCharges();
TotalCharges();
}
private void ClearButton_Click(object sender, EventArgs e)
{
oilCheckBox.Checked = false;
lubeCheckBox.Checked = false;
radFlushBox.Checked = false;
tranFlushBox.Checked = false;
insCheckBox.Checked = false;
mufCheckBox.Checked = false;
tireCheckBox.Checked = false;
partsTextBox.Text = "";
laborTextBox.Text = "";
serLabTotalTextBox.Text = "";
partsTotalTextBox.Text = "";
taxPartsTextBox.Text = "";
totalFeesTextBox.Text = "";
}
private void ExitButton_Click(object sender, EventArgs e)
{
this.Close();
}
private int OilLubeCharges()
{
int total = 0;
if (oilCheckBox.Checked)
{
total += 26;
serLabTotalTextBox.Text = total.ToString("c");
}
if (lubeCheckBox.Checked)
{
total += 18;
serLabTotalTextBox.Text = total.ToString("c");
return total;
}
else
{
return total;
}
}
private int FlushCharges()
{
int total = 0;
if (radFlushBox.Checked)
{
total += 30;
serLabTotalTextBox.Text = total.ToString("c");
}
if (tranFlushBox.Checked)
{
total += 80;
serLabTotalTextBox.Text = total.ToString("c");
return total;
}
else
{
return total;
}
}
private int MiscCharges()
{
int total = 0;
if (insCheckBox.Checked)
{
total += 15;
serLabTotalTextBox.Text = total.ToString("c");
}
if (mufCheckBox.Checked)
{
total += 100;
serLabTotalTextBox.Text = total.ToString("c");
}
if (tireCheckBox.Checked)
{
total += 20;
serLabTotalTextBox.Text = total.ToString("c");
return total;
}
else
{
return total;
}
}
private int OtherCharges()
{
int total = 0;
int parts = 0;
int labor = 0;
if (int.TryParse(partsTextBox.Text, out parts))
{
partsTextBox.Text = parts.ToString("c");
total = parts;
}
if (int.TryParse(laborTextBox.Text, out labor))
{
laborTextBox.Text = labor.ToString("c");
return total;
}
else
{
return total;
}
}
private decimal TaxCharges()
{
decimal parts = 0;
decimal partsTax;
partsTax = parts * .06m;
taxPartsTextBox.Text = partsTax.ToString("c");
return partsTax;
}
private decimal TotalCharges()
{
decimal total = 0;
total = OilLubeCharges() + FlushCharges() + MiscCharges() + TaxCharges() + OtherCharges();
totalFeesTextBox.Text = total.ToString("c");
return total;
}
}
【问题讨论】:
-
我会确保计算、清除和退出按钮事件方法(CalcButton_Click、ClearButton_Click、ExitButton_Click)正确连接到 UI 上按钮上的相应点击事件。如果是,在事件中设置断点将帮助您调试实际发生的情况。
-
通过添加断点 (F9) 和单步调试代码 (F11) 来调试代码。您可能没有获得所有代码,如果没有更多信息,我们将无法提供帮助。
-
尝试使用断点或旧的
MessageBox.Show()来验证事件是否被调用。 -
我应该把这些放在哪里?我尝试了几次不同的时间并弹出一个窗口,但没有任何反应。
-
特殊的“计算、清除、退出按钮也不起作用”表示事件没有在设计器端注册。
标签: c# visual-studio methods