这是我用SharpDevelop编写的计算器的代码 . 我需要知道如何覆盖一个数字 .
在我的代码中,当我发短信第一个号码时,按下添加按钮后,文本框被清除 .
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
double total1 = 0;
double total2 = 0;
void BtnOneClick(Object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnOne.Text;
}
void BtnTwoClick(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnTwo.Text;
}
...
void BtnZeroClick(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnZero.Text;
}
void BtnClearClick(object sender, EventArgs e)
{
txtDisplay.Clear();
}
void BtnPlusClick(object sender, EventArgs e)
{
total1 += double.Parse(txtDisplay.Text);
txtDisplay.Clear();
plusButtonClicked = true;
minusButtonClicked = false;
multiplyButtonClicked = false;
divideButtonClicked = false;
}
...
bool plusButtonClicked = false;
bool minusButtonClicked = false;
bool multiplyButtonClicked = false;
bool divideButtonClicked = false;
}
2 回答
我想你想要的
Edit:
.Clear
将从文本框中删除文本..我想如果您想要其他事情发生,那么您需要重新考虑您要做的事情Edit2 如果这不是你想要的我不知道是什么
这是因为这一行:txtDisplay.Clear();在你的方法BtnPlusClick();
如果你只想在你开始提供下一个数字时清除它 - 只需chceck你的bool标志(加上按钮等等) - 如果它们被设置为true - 那么make txtDisplay.Clear();