问题描述
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespaceWindowsFormsApplication1{publicpartialclass计算器:Form{privatestringa=null;privatestringb=null;privatedoublec=0;privatestringsign=null;privatebooldian=false;public计算器(){InitializeComponent();}privatevoidbutton11_Click(objectsender,EventArgse){if(a!=null&&a!="0"){a=a+"0";}elseif(a==null){a="0";}textBox1.Text=a;}privatevoidbutton12_Click(objectsender,EventArgse){if(a!=null&&a!="0"){a=a+"1";}elseif(a==null){a="1";}textBox1.Text=a;}privatevoidbutton7_Click(objectsender,EventArgse){if(dian==false){dian=true;if(a!=null){a=a+".";}else{a="0.";}textBox1.Text=a;}}privatevoidbutton15_Click(objectsender,EventArgse){if(sign==null){sign="+";b=a;a=null;dian=false;}}privatevoidbutton8_Click(objectsender,EventArgse){if(a!=null&&a!="0"){a=a+"2";}elseif(a==null){a="2";}textBox1.Text=a;}privatevoidbutton10_Click(objectsender,EventArgse){if(sign=="+"){c=Convert.ToDouble(a)+Convert.ToDouble(b);}if(sign=="-"){c=Convert.ToDouble(b)-Convert.ToDouble(a);}if(sign=="*"){c=Convert.ToDouble(a)*Convert.ToDouble(b);}if(sign=="/"){c=Convert.ToDouble(b)/Convert.ToDouble(a);}textBox1.Text=Convert.ToString(c);}privatevoidbutton4_Click(objectsender,EventArgse){if(a!=null&&a!="0"){a=a+"3";}elseif(a==null){a="3";}textBox1.Text=a;}privatevoidbutton13_Click(objectsender,EventArgse){if(a!=null&&a!="0"){a=a+"4";}elseif(a==null){a="4";}textBox1.Text=a;}privatevoidbutton9_Click(objectsender,EventArgse){if(a!=null&&a!="0"){a=a+"5";}elseif(a==null){a="5";}textBox1.Text=a;}privatevoidbutton5_Click(objectsender,EventArgse){if(a!=null&&a!="0"){a=a+"6";}elseif(a==null){a="6";}textBox1.Text=a;}privatevoidbutton1_Click(objectsender,EventArgse){if(a!=null&&a!="0"){a=a+"7";}elseif(a==null){a="7";}textBox1.Text=a;}privatevoidbutton17_Click(objectsender,EventArgse){if(a!=null&&a!="0"){a=a+"8";}elseif(a==null){a="8";}textBox1.Text=a;}privatevoidbutton16_Click(objectsender,EventArgse){if(a!=null&&a!="0"){a=a+"9";}elseif(a==null){a="9";}textBox1.Text=a;}privatevoidbutton2_Click(objectsender,EventArgse){if(sign==null){sign="-";b=a;a=null;dian=false;}}privatevoidbutton6_Click(objectsender,EventArgse){if(sign==null){sign="*";b=a;a=null;dian=false;}}privatevoidbutton3_Click(objectsender,EventArgse){if(sign==null){sign="/";b=a;a=null;dian=false;}}privatevoidbutton14_Click(objectsender,EventArgse){textBox1.Text="0";c=0;a=null;b=null;dian=false;sign=null;}}}
解决方案
解决方案二:
建议你去网上看看别人的计算器实现思路。你这完全拖控件写代码啊,谁能有空给你找bug呢
解决方案三:
什么叫“看里边的bug”?贴出你的调试画面来。
解决方案四:
解决方案五:
这么多同样代码你不累吗?。。不知道绑定同一个事件吗?
解决方案六:
最好在button控件的事件里绑定一个方法,这样代码比较简洁,bug也好找,而且你可以调试一下在说出bug。一大串的看过去很烦的
解决方案七:
好吧我和大家一样不打算看代码……提个建议,既然开始写小项目了,就不要一直intaintb这种了……慢慢挑吧会打断点么?