0
我試圖寫一個計算器中計算作爲一個網站,如何解決類值初始化每個回發
我設置2個變量在我的課存儲號碼,
,但每次我點擊了「 +「或」 - 「按鈕,
變量返回到初始資源。
這裏是我的代碼:
public partial class _Default : System.Web.UI.Page
{
int choice = 0;
Boolean caluOrNot = false;
double before, after;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Btn1_Click(object sender, EventArgs e)
{
if (this.caluOrNot == false)
{
if (txtResult.Text.ToString() == "0")
{
txtResult.Text = "1";
}
else
{
txtResult.Text += "1";
}
}
else
{
txtResult.Text = "1";
}
}
protected void Btn2_Click(object sender, EventArgs e)
protected void Btn3_Click(object sender, EventArgs e)
protected void Btn4_Click(object sender, EventArgs e)
protected void Btn5_Click(object sender, EventArgs e)
protected void Btn6_Click(object sender, EventArgs e)
protected void Btn7_Click(object sender, EventArgs e)
protected void Btn8_Click(object sender, EventArgs e)
protected void Btn9_Click(object sender, EventArgs e)
protected void Btn0_Click(object sender, EventArgs e)
protected void BtnPoint_Click(object sender, EventArgs e)
{
txtResult.Text += ".";
}
protected void BtnJia_Click(object sender, EventArgs e)
{
this.choice = 1;
this.caluOrNot = true;
before = Double.Parse(txtResult.Text.ToString());
txtCalu.Text = before.ToString() + "+";
}
protected void BtnJen_Click(object sender, EventArgs e)
protected void BtnCheng_Click(object sender, EventArgs e)
protected void BtnChu_Click(object sender, EventArgs e)
protected void btnClear_Click(object sender, EventArgs e)
{
txtResult.Text = "0";
this.choice = 0;
}
protected void btnGo_Click(object sender, EventArgs e)
{
double a;
switch (this.choice)
{
case 1:
a = before + after;
txtResult.Text = a.ToString();
break;
case 2:
a = before - after;
txtResult.Text = a.ToString();
break;
case 3:
a = before * after;
txtResult.Text = a.ToString();
break;
case 4:
a = before/after;
txtResult.Text = a.ToString();
break;
default:
break;
}
}
}
爲TH代碼,每次我點擊btnJia
將觸發的onclick方法BtnJia_Click
選擇將 「1」 和caculOrNot
組設置爲true,但值將變回0,並在BtnJia_Click
完成時爲false。
我該如何解決?
我無法編譯您的代碼.'保護無效Btn0_Click(對象發件人,EventArgs e)',其中是';'? – 2013-03-05 06:53:07