C#实现的简单整数四则运算计算器功能示例-创新互联
本文实例讲述了C#实现的简单整数四则运算计算器功能。分享给大家供大家参考,具体如下:
新荣网站建设公司创新互联,新荣网站设计制作,有大型网站制作公司丰富经验。已为新荣上千提供企业网站建设服务。企业网站搭建\成都外贸网站建设公司要多少钱,请找那个售后服务好的新荣做网站的公司定做!运行效果图如下:
具体代码如下:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace 计算器 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public string num; public int flag;//用于判断输入的操作符 public double num1, num2; private void num0_button_Click(object sender, EventArgs e) { num = num + "0"; num2 = Convert.ToDouble(num); textBox.Text = num; } private void num1_button_Click(object sender, EventArgs e)//重点算法1 { if (textBox.Text == "0") { num = "1"; textBox.Text = Convert.ToString(num); } else { num = num + "1"; num2 = Convert.ToDouble(num); textBox.Text = num; } } private void num2_button_Click(object sender, EventArgs e) { if (textBox.Text == "0") { num = "2"; textBox.Text = Convert.ToString(num); } else { num = num + "2"; num2 = Convert.ToDouble(num); textBox.Text = num; } } private void num3_button_Click(object sender, EventArgs e) { if (textBox.Text == "0") { num = "3"; textBox.Text = Convert.ToString(num); } else { num = num + "3"; num2 = Convert.ToDouble(num); textBox.Text = num; } } private void num4_button_Click(object sender, EventArgs e) { if (textBox.Text == "0") { num = "4"; textBox.Text = Convert.ToString(num); } else { num = num + "4"; num2 = Convert.ToDouble(num); textBox.Text = num; } } private void num5_button_Click(object sender, EventArgs e) { if (textBox.Text == "0") { num = "5"; textBox.Text = Convert.ToString(num); } else { num = num + "5"; num2 = Convert.ToDouble(num); textBox.Text = num; } } private void num6_button_Click(object sender, EventArgs e) { if (textBox.Text == "0") { num = "6"; textBox.Text = Convert.ToString(num); } else { num = num + "6"; num2 = Convert.ToDouble(num); textBox.Text = num; } } private void num7_button_Click(object sender, EventArgs e) { if (textBox.Text == "0") { num = "7"; textBox.Text = Convert.ToString(num); } else { num = num + "7"; num2 = Convert.ToDouble(num); textBox.Text = num; } } private void num8_button_Click(object sender, EventArgs e) { if (textBox.Text == "0") { num = "8"; textBox.Text = Convert.ToString(num); } else { num = num + "8"; num2 = Convert.ToDouble(num); textBox.Text = num; } } private void num9_button_Click(object sender, EventArgs e) { if (textBox.Text == "0") { num = "9"; textBox.Text = Convert.ToString(num); } else { num = num + "9"; num2 = Convert.ToDouble(num); textBox.Text = num; } } private void add_button_Click(object sender, EventArgs e)//重点算法2 { if (textBox.Text.Length > 0) { num1 = Convert.ToDouble(textBox .Text); num = ""; flag = 1; textBox.Text = ""; textBox.Focus(); } } private void dev_button_Click(object sender, EventArgs e) { if (textBox.Text.Length > 0) { num1 = Convert.ToDouble(textBox.Text); num = ""; flag = 2; textBox.Text = ""; textBox.Focus(); } } private void mul_button_Click(object sender, EventArgs e) { if (textBox.Text.Length > 0) { num1 = Convert.ToDouble(textBox.Text); num = ""; flag = 3; textBox.Text = ""; textBox.Focus(); } } private void chu_button_Click(object sender, EventArgs e) { if (textBox.Text.Length > 0) { num1 = Convert.ToDouble(textBox.Text); num = ""; flag = 4; // textBox.Text = ""; textBox.Focus(); } } private void equ_button_Click(object sender, EventArgs e) { switch (flag) { case 1: textBox.Text = Convert.ToString(num1+Convert .ToDouble(num));//重点算法3 num2 = Convert.ToDouble(textBox .Text); break; case 2: textBox.Text = Convert.ToString(num1 - Convert.ToDouble(num)); num2 = Convert.ToDouble(textBox.Text); break; case 3: textBox.Text = Convert.ToString(num1 * Convert.ToDouble(num)); num2 = Convert.ToDouble(textBox.Text); break; case 4: textBox.Text = Convert.ToString(num1 / Convert.ToDouble(num)); num2 = Convert.ToDouble(textBox.Text); break; } } private void re_button_Click(object sender, EventArgs e) { num = ""; textBox.Text = "0"; } } }
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
分享标题:C#实现的简单整数四则运算计算器功能示例-创新互联
当前URL:http://scyanting.com/article/dsehsc.html