public partial class Form1: Form {
// Define a few variables
int InputInteger;
int HoldInteger;
int OutputInteger;
public Form1() {
InitializeComponent();
}
private void exitBtn_Click(object sender, EventArgs e) {
//Used to close the form when exit is clicked
this.Close();
}
private void clearBtn_Click(object sender, EventArgs e) {
//this will deselect all of the radio buttons, along with clearing the
// textboxes with input and output information.
depositBtn.Checked = false;
checksBtn.Checked = false;
serviceBtn.Checked = false;
inputTxt.Clear();
outputTxt.Clear();
}
private void calculateBtn_Click(object sender, EventArgs e) {
// Calculate button actions
try {
InputInteger = Convert.ToInt32(inputTxt.Text);
// For each radio button checked gives an action to the calculate button
if (depositBtn.Checked == true); {
OutputInteger = (InputInteger + HoldInteger);
outputTxt.Text = OutputInteger.ToString();
} else if (checksBtn.Checked == true); {
if (InputInteger > OutputInteger); {
OutputInteger = (HoldInteger - 10);
outputTxt.Text = OutputInteger.ToString();
MessageBox.Show("Insufficient Funds");
if (HoldInteger < 0); {
MessageBox.Show("Negative account balance");
}
} else if (InputInteger <= HoldInteger); {
OutputInteger = (InputInteger - HoldInteger);
outputTxt.Text = OutputInteger.ToString();
}
} else if (serviceBtn.Checked); {
if (InputInteger > OutputInteger); {
OutputInteger = (HoldInteger - 10);
outputTxt.Text = OutputInteger.ToString();
MessageBox.Show("Insufficient Funds");
if (HoldInteger < 0); {
MessageBox.Show("Negative account balance");
}
} else if (InputInteger <= HoldInteger); {
OutputInteger = (InputInteger - HoldInteger);
outputTxt.Text = OutputInteger.ToString();
}
}
} catch {
}
}
private void outputTxt_TextChanged(object sender, EventArgs e) {
}
}
}
我的read-only outputTxt文本框中没有任何文本。任何帮助表示赞赏。我需要在Calculate按钮的每次单击事件后显示outputTxt。我使用HoldInteger来保存outputinteger的中间计算,这应该是每个单选按钮选择的最终输出。My form
答案 0 :(得分:7)
您需要从每个;
语句的末尾删除if
。
更改
if (depositBtn.Checked == true) ;
到
if (depositBtn.Checked == true)
在;
声明之后使用if
的所有地方都这样做。
这是因为如果您在;
语句之后使用if
,那么您实际上是在添加一个空脚本块。这些代码基本相同:
// this code block
if (depositBtn.Checked == true);
{
OutputInteger = (InputInteger + HoldInteger);
outputTxt.Text = OutputInteger.ToString();
}
//is identical to
if (depositBtn.Checked == true)
{
}
{
OutputInteger = (InputInteger + HoldInteger);
outputTxt.Text = OutputInteger.ToString();
}
答案 1 :(得分:0)
一切都很好,除了;在if(condition);
之后
移除所有 ;就在条件陈述之后。写得像if(condition){}
那你很高兴。