计算器简单封装和ASP.net
2015-11-29 16:26
701 查看
封装:
usingSystem; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Text; namespace计算器 { classRichnone { publicstringfuhao;//计算符号 publicdoubleresult;//计算结果 privatedoublex;//第一个数 publicdoubleX { get{returnx;} set{x=value;} } privatedoubley;//第二个数 publicdoubleY { get{returny;} set{y=value;} } publicvoidAdd()//加法 { if(fuhao=="+") { result=X+Y; } } publicvoidSub()//减法 { if(fuhao=="-") { result=X-Y; } } publicvoidMul()//乘法 { if(fuhao=="*") { result=X*Y; } } publicvoidDiv()//除法 { if(fuhao=="/") { result=X/Y; } } } } Form1代码
privatevoidForm1_Load(objectsender,EventArgse) { if(File.Exists(path)) { this.richTextBox1.LoadFile(path,RichTextBoxStreamType.RichText); open.Enabled=true; } save.Enabled=true; } privatevoidopen_Click(objectsender,EventArgse) { OpenFileDialogTxTOPenDialog=newOpenFileDialog(); TxTOPenDialog.Filter="RTF文件(*.RTF)|*.RTF"; if(TxTOPenDialog.ShowDialog()==DialogResult.OK) { path=TxTOPenDialog.FileName; this.richTextBox1.LoadFile(TxTOPenDialog.FileName,RichTextBoxStreamType.RichText); open.Enabled=true; save.Enabled=true; MessageBox.Show("读取成功!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Asterisk); this.richTextBox1.Show(); } } privatevoidsave_Click(objectsender,EventArgse) { SaveFileDialogTxTSaveDialog=newSaveFileDialog(); TxTSaveDialog.Filter="RTF文件(*.RTF)|*.RTF"; richTextBox1.Text=textBox2.Text; if(File.Exists(path)) { this.richTextBox1.SaveFile(path,RichTextBoxStreamType.RichText); MessageBox.Show("保存成功!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Asterisk); this.richTextBox1.Clear(); save.Enabled=false; } else { if(TxTSaveDialog.ShowDialog()==DialogResult.OK) { this.richTextBox1.SaveFile(TxTSaveDialog.FileName,RichTextBoxStreamType.RichText); MessageBox.Show("保存成功!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Asterisk); this.richTextBox1.Clear(); save.Enabled=false; } } } privatevoidadd_Click(objectsender,EventArgse) { SUAN.Text="+"; } privatevoidsub_Click(objectsender,EventArgse) { SUAN.Text="-"; } privatevoidmul_Click(objectsender,EventArgse) { SUAN.Text="*"; } privatevoiddiv_Click_1(objectsender,EventArgse) { SUAN.Text="/"; } //实例对象 Richnoneric=newRichnone(); ric.X=double.Parse(richTextBox1.Text);//第一个数 ric.Y=double.Parse(textBox2.Text);//第二个数 ric.fuhao=SUAN.Text;//运算符号 ric.result=result;//结果 ric.Add();//加法 ric.Sub();//减法 ric.Mul();//乘法 ric.Div();//除法 //intsum; //sum=int.Parse(richTextBox1.Text)+int.Parse(textBox2.Text); if(e.KeyCode==Keys.Enter) { if(textBox5.Text==ric.result.ToString()) { right++; MessageBox.Show("回答正确!"); } else { MessageBox.Show("回答错误!"); } Count++; richTextBox1.Clear(); textBox2.Clear(); textBox5.Clear(); } }截图
ASP.net 后台代码
protectedvoidButton1_Click(objectsender,EventArgse) { ric.X=double.Parse(TextBox1.Text); ric.Y=double.Parse(TextBox3.Text); ric.fuhao=DropDownList1.SelectedValue; ric.result=result; ric.Add(); ric.Sub(); ric.Mul(); ric.Div(); if(TextBox4.Text==ric.result.ToString()) { Response.Write("<script>alert('回答正确')</script>"); } else { Response.Write("<script>alert('回答错误')</script>"); } } protectedvoidDropDownList1_TextChanged(objectsender,EventArgse) { stringfuhao=DropDownList1.SelectedValue; switch(fuhao) { case"+": DropDownList1.SelectedValue="+"; break; case"-": DropDownList1.SelectedValue="-"; break; case"*": DropDownList1.SelectedValue="*"; break; case"/": DropDownList1.SelectedValue="/"; break; default: break; } } 封装
publicclassRichnone { publicstringfuhao;//计算符号 publicdoubleresult; privatedoublex;//第一个数 publicdoubleX { get{returnx;} set{x=value;} } privatedoubley;//第二个数 publicdoubleY { get{returny;} set{y=value;} } publicvoidAdd()//加法 { if(fuhao=="+") { result=X+Y; } } publicvoidSub() { if(fuhao=="-") { result=X-Y; } } publicvoidMul() { if(fuhao=="*") { result=X*Y; } } publicvoidDiv() { if(fuhao=="/") { result=X/Y; } } } 截图
相关文章推荐
- ASP.net封装
- 计算器软件的代码实现 (策略模式+asp.net)
- 本地发布asp.net程序
- ASP.NET实现学生管理系统
- ASP.NET中实现封装与策略模式
- Response.Redirect("x.aspx);跳转后session为null的解决方法
- asp.net 母版页使用详解
- ASP.NET MVC- 解决HTML转码
- asp.net的快捷实用分页类
- ASP.NET实现学生管理系统
- asp.net关于Cookie跨域(域名)的问题
- ASP.NET中Cookie的使用
- asp.net中使用getElementById的注意点
- ASP.NET WebAPI 14 仿写Filter管道
- ASP.NET常用的弹窗方法
- metasploit基础
- Asp.Net MVC 教程汇总
- asp.net实现输出xml的方法
- 封装,策略,Asp换脸
- ASP.NET MVC- KindEditor的使用