标签:string Show C# i2 EventArgs i1 int 计算器 所示
1.题目要求如下:
C#设计一个简单的计算器,实现两个数的加,减,乘,除,求幂等计算,运行效果如下图所示:
2.这边需要用到的是VS2019下的C#Windows窗体
3.来吧,展示:
using System; using System.Windows.Forms; namespace Calculator { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { MessageBox.Show("欢迎使用小关牌计算器!"); } private void button1_Click(object sender, EventArgs e) { try { string s1 = textBox1.Text; string s2 = textBox2.Text; int i1, i2; i1 = (int)Convert.ToInt64(s1); i2 = (int)Convert.ToInt64(s2); string s3 = (i1 + i2).ToString(); MessageBox.Show(s3); } catch { MessageBox.Show("错误,请检查!"); } } private void button3_Click(object sender, EventArgs e) { try { string s1 = textBox1.Text; string s2 = textBox2.Text; double i1, i2; i1 = (int)Convert.ToInt64(s1); i2 = (int)Convert.ToInt64(s2); string s3 = (i1 / i2).ToString(); MessageBox.Show(s3); } catch { MessageBox.Show("错误,请检查!"); } } private void textBox1_TextChanged(object sender, EventArgs e) { } private void label2_Click(object sender, EventArgs e) { MessageBox.Show("目前不支持其他运算!"); } private void label3_Click(object sender, EventArgs e) { } private void textBox3_TextChanged(object sender, EventArgs e) { } private void textBox2_TextChanged(object sender, EventArgs e) { } private void button1_Click_1(object sender, EventArgs e) { try { string s1 = textBox1.Text; string s2 = textBox2.Text; int i1, i2; i1 = (int)Convert.ToInt64(s1); i2 = (int)Convert.ToInt64(s2); string s3 = (i1 - i2).ToString(); MessageBox.Show(s3); } catch { MessageBox.Show("错误,请检查!"); } } private void button2_Click(object sender, EventArgs e) { try { string s1 = textBox1.Text; string s2 = textBox2.Text; int i1, i2; i1 = (int)Convert.ToInt64(s1); i2 = (int)Convert.ToInt64(s2); string s3 = (i1 * i2).ToString(); MessageBox.Show(s3); } catch { MessageBox.Show("错误,请检查!"); } } private void button4_Click(object sender, EventArgs e) { try { string s1 = textBox1.Text; string s2 = textBox2.Text; int i1, i2; i1 = (int)Convert.ToInt64(s1); i2 = (int)Convert.ToInt64(s2); double s3 = Math.Pow(i1, i2); string s4 = Convert.ToString(s3); MessageBox.Show(s4); } catch { MessageBox.Show("错误,请检查!"); } } private void button5_Click(object sender, EventArgs e) { //归零 textBox1.Text = string.Empty; textBox2.Text = string.Empty; } } }
这个有140多行代码稍微有点长,有待改善
4.来看看运行结果:ctrl+f5
这边自由发挥加上了弹窗提示的效果
这边演示的为9的9次方结果
希望能帮到大家,问你们要一个赞,你们会给吗,谢谢大家
版权声明:本文版权归作者(@攻城狮小关)和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
大家写文都不容易,请尊重劳动成果~
交流加Q:1909561302
CSDN地址https://blog.csdn.net/Mumaren6/
标签:string,Show,C#,i2,EventArgs,i1,int,计算器,所示 来源: https://www.cnblogs.com/guanguan-com/p/13876815.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。