大家好,谁有计算器(C#版)的源码 谢谢大家, 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 有bug哈 /// <summary> /// 第一个数 /// </summary> private int Num1 { get { return Convert.ToInt32(ViewState["Num1"]); } set { ViewState["Num1"]=value; } } /// <summary> /// 运算符 /// </summary> private string FH { get { return Convert.ToString(ViewState["FH"]); } set { ViewState["FH"] =value; } } /// <summary> /// 第二个数 /// </summary> private int Num2 { get { return Convert.ToInt32(ViewState["Num2"]); } set { ViewState["Num2"] = value; } } // 0-9 protected void Button1_Click(object sender, EventArgs e) { Button button = sender as Button; Response.Write(button.Text); if (ViewState.Count == 0) { if (Convert.ToInt32(button.Text.Trim()) >= 0 && Convert.ToInt32(button.Text.Trim()) <= 9) { this.Label1.Text += button.Text.Trim(); } else { Response.Write("<script>alert('请选择第一个运算数!')</script>"); } } else if (ViewState.Count == 2) { if (Convert.ToInt32(button.Text.Trim()) >= 0 && Convert.ToInt32(button.Text.Trim()) <= 9) { if (this.Label1.Text.Trim() == "+") { this.Label1.Text = ""; } this.Label1.Text += button.Text.Trim(); } else { Response.Write("<script>alert('请选择第二个运算数!')</script>"); } } //Response.Write("<script>alert('" + ViewState.Count.ToString() + "')</script>"); } /// <summary> /// 点击"="按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Button11_Click(object sender, EventArgs e) { if (ViewState.Count == 2) { Num2=Convert.ToInt32(this.Label1.Text.Trim()); Response.Write("<script>alert('" + Num1 + "')</script>"); Response.Write("<script>alert('" + FH + "')</script>"); Response.Write("<script>alert('" + Num2 + "')</script>"); switch (FH) { case "+": this.Label1.Text = Convert.ToString(Num1 + Num2); break; case "-": this.Label1.Text = Convert.ToString(Num1 - Num2); break; case "*": this.Label1.Text = Convert.ToString(Num1 * Num2); break; case "/": this.Label1.Text = Convert.ToString(Num1 / Num2); break; } } } /// <summary> /// 清空 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Button5_Click(object sender, EventArgs e) { Response.Write("<script>alert('" + ViewState.Count.ToString() + "')</script>"); ViewState.Clear(); //吧viewState全部情空 Response.Write("<script>alert('" + ViewState.Count.ToString() + "')</script>"); this.Label1.Text = ""; } /// <summary> /// 去掉一个"> -" /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Button6_Click(object sender, EventArgs e) { if (this.Label1.Text != "" && this.Label1.Text.Length != 1) { this.Label1.Text = this.Label1.Text.Substring(0, this.Label1.Text.Length - 1); } else { this.Label1.Text = ""; } } /// <summary> /// ‘ + ’ ‘ - ’ ' * ' '/ ' /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Button4_Click(object sender, EventArgs e) { Button button = sender as Button; if (ViewState.Count == 0 && this.Label1.Text.Trim() != "") { Num1 = Convert.ToInt32(this.Label1.Text.Trim()); //存储第一个数 this.Label1.Text = button.Text.Trim(); //把运算符赋值给Label控件 FH = this.Label1.Text.Trim(); //存储运算符 } } 计算器?应该不难吧,后面处理可以直接用Math里的东西。 打开VS2005设计窗体出错 关于DataList控件和Repeater控件绑定问题?(求助高手) 关于remoting的问题,很简单 如何在类中输出显示一个字符串 .Net精简框架中的模拟键盘输入的问题 小弟初学c# 问一个关于接口继承的问题请那位大虾解决以下 请教关于WPF 窗体焦点问题 开发window form在没有像在web form的imagemap的控件阿---急用! C#版完成端口,包括服务器、客户端、上传协议等介绍 不用水晶报表,如何打印较大的报表? 如何实现picturebox拖拽改变大小 用.net从PLC里面读出数据的问题
有bug哈 /// <summary>
/// 第一个数
/// </summary> private int Num1
{
get { return Convert.ToInt32(ViewState["Num1"]); }
set { ViewState["Num1"]=value; }
} /// <summary>
/// 运算符
/// </summary>
private string FH
{
get { return Convert.ToString(ViewState["FH"]); }
set { ViewState["FH"] =value; }
} /// <summary>
/// 第二个数
/// </summary>
private int Num2
{
get { return Convert.ToInt32(ViewState["Num2"]); }
set { ViewState["Num2"] = value; }
}
// 0-9
protected void Button1_Click(object sender, EventArgs e)
{
Button button = sender as Button;
Response.Write(button.Text);
if (ViewState.Count == 0)
{
if (Convert.ToInt32(button.Text.Trim()) >= 0 && Convert.ToInt32(button.Text.Trim()) <= 9)
{
this.Label1.Text += button.Text.Trim();
}
else
{
Response.Write("<script>alert('请选择第一个运算数!')</script>");
}
}
else if (ViewState.Count == 2)
{
if (Convert.ToInt32(button.Text.Trim()) >= 0 && Convert.ToInt32(button.Text.Trim()) <= 9)
{
if (this.Label1.Text.Trim() == "+")
{
this.Label1.Text = "";
}
this.Label1.Text += button.Text.Trim();
}
else
{
Response.Write("<script>alert('请选择第二个运算数!')</script>");
} } //Response.Write("<script>alert('" + ViewState.Count.ToString() + "')</script>");
} /// <summary>
/// 点击"="按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Button11_Click(object sender, EventArgs e)
{
if (ViewState.Count == 2)
{
Num2=Convert.ToInt32(this.Label1.Text.Trim());
Response.Write("<script>alert('" + Num1 + "')</script>");
Response.Write("<script>alert('" + FH + "')</script>");
Response.Write("<script>alert('" + Num2 + "')</script>");
switch (FH)
{
case "+":
this.Label1.Text = Convert.ToString(Num1 + Num2);
break;
case "-":
this.Label1.Text = Convert.ToString(Num1 - Num2);
break;
case "*":
this.Label1.Text = Convert.ToString(Num1 * Num2);
break;
case "/":
this.Label1.Text = Convert.ToString(Num1 / Num2);
break;
}
}
} /// <summary>
/// 清空
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Button5_Click(object sender, EventArgs e)
{
Response.Write("<script>alert('" + ViewState.Count.ToString() + "')</script>");
ViewState.Clear(); //吧viewState全部情空
Response.Write("<script>alert('" + ViewState.Count.ToString() + "')</script>");
this.Label1.Text = "";
}
/// <summary>
/// 去掉一个"> -"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Button6_Click(object sender, EventArgs e)
{
if (this.Label1.Text != "" && this.Label1.Text.Length != 1)
{
this.Label1.Text = this.Label1.Text.Substring(0, this.Label1.Text.Length - 1);
}
else
{
this.Label1.Text = "";
}
} /// <summary>
/// ‘ + ’ ‘ - ’ ' * ' '/ '
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Button4_Click(object sender, EventArgs e)
{
Button button = sender as Button;
if (ViewState.Count == 0 && this.Label1.Text.Trim() != "")
{
Num1 = Convert.ToInt32(this.Label1.Text.Trim()); //存储第一个数
this.Label1.Text = button.Text.Trim(); //把运算符赋值给Label控件
FH = this.Label1.Text.Trim(); //存储运算符
}
}