文件名称:
VS不用人教自己看自己学两小时做的小计算器
开发工具:
文件大小: 16kb
下载次数: 0
上传时间: 2010-05-26
详细说明: 什么好玩做什么 namespace WindowsFormsApplication1 { public partial class Form1 : Form { Double first = 0; String second = null; int code = 0; String result = null; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void button(String sender) { if (result != null) { textBox1.Clear(); } if (code != 0 && second == null) { textBox1.Clear (); } String b = sender; if (textBox1.Text == null || textBox1.Text == "") { textBox1.Text = b; } else { textBox1.Text = textBox1.Text + b; } if (code != 0) { second = textBox1.Text; } result = null; label1.Focus(); } private void button1_Click(object sender, EventArgs e) { button("1"); } private void button2_Click(object sender, EventArgs e) { button("2"); } private void button3_Click(object sender, EventArgs e) { button("3"); } private void button4_Click(object sender, EventArgs e) { button("4"); } private void button5_Click(object sender, EventArgs e) { button("5"); } private void button6_Click(object sender, EventArgs e) { button("6"); } private void button7_Click(object sender, EventArgs e) { button("7"); } private void button8_Click(object sender, EventArgs e) { button("8"); } private void button9_Click(object sender, EventArgs e) { button("9"); } private void button10_Click(object sender, EventArgs e) { if (textBox1.Text == null || textBox1.Text == "") { button("0"); }else if (Convert.ToDouble(textBox1.Text) != 0) { button("0"); }else if (textBox1.Text.IndexOf(".") == 1) { button("0"); } label1.Focus(); } private void button11_Click(object sender, EventArgs e) { if (second == null) { MessageBox.Show("哥们你要算什么啊?麻烦再输入数!"); } else if (Convert.ToDouble(second) == 0 && first != 0 && code == 4) { textBox1.Text = "除数不能为零!"; } else { switch (code) { case 1: textBox1.Text = Convert.ToString(first + Convert.ToDouble(textBox1.Text)); break; case 2: textBox1.Text = Convert.ToString(first - Convert.ToDouble(textBox1.Text)); break; case 3: textBox1.Text = Convert.ToString(first * Convert.ToDouble(textBox1.Text)); break; case 4: textBox1.Text = Convert.ToString(first / Convert.ToDouble(textBox1.Text)); break; } } first = 0; second = null; code = 0; result = textBox1.Text; label1.Focus(); } private void button12_Click(object sender, EventArgs e) { if (Convert.ToDouble(textBox1.Text) != 0 || textBox1.Text == null || textBox1.Text == "") { button("00"); } else if (textBox1.Text.IndexOf(".") == 1) { button("00"); } label1.Focus(); } private void button17_Click(object sender, EventArgs e) { if (textBox1.Text.IndexOf(".") < 1) { button("."); } label1.Focus(); } private void button_2() { if (textBox1.Text == null || textBox1.Text == "") { first = 0; } else if (first == 0) { first = Convert.ToDouble(textBox1.Text); } } private void button18_Click(object sender, EventArgs e) { button_2(); code = 4; label1.Focus(); } private void button13_Click(object sender, EventArgs e) { button_2(); code = 2; label1.Focus(); } private void button14_Click(object sender, EventArgs e) { button_2(); code = 3; label1.Focus(); } private void button15_Click(object sender, EventArgs e) { button_2(); code = 1; label1.Focus(); } private void button16_Click(object sender, EventArgs e) { textBox1.Clear(); label1.Focus(); } private void Form1_KeyUp(object sender, KeyEventArgs e) { //MessageBox.Show(Convert.ToString(e.KeyCode)); if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Oemplus) { button11_Click(null, null); } else if (e.KeyCode == Keys.Divide || e.KeyCode == Keys.OemQuestion) { button18_Click(null, null); } else if (e.KeyCode == Keys.Add || e.KeyCode == Keys.Oemplus) { button15_Click(null, null); } else if (e.KeyCode == Keys.Multiply) { button14_Click(null, null); } else if (e.KeyCode == Keys.Subtract || e.KeyCode == Keys.OemMinus) { button13_Click(null, null); } else if (e.KeyCode == Keys.OemPeriod || e.KeyCode == Keys.Delete) { button17_Click(null, null); } else if (e.KeyCode == Keys.Oemtilde) { button12_Click(null, null); } else if (e.KeyCode == Keys.D1 || e.KeyCode == Keys.NumPad1) { button1_Click(null, null); } else if (e.KeyCode == Keys.D2 || e.KeyCode == Keys.NumPad2) { button2_Click(null, null); } else if (e.KeyCode == Keys.D3 || e.KeyCode == Keys.NumPad3) { button3_Click(null, null); } else if (e.KeyCode == Keys.D4 || e.KeyCode == Keys.NumPad4) { button4_Click(null, null); } else if (e.KeyCode == Keys.D5 || e.KeyCode == Keys.NumPad5) { button5_Click(null, null); } else if (e.KeyCode == Keys.D6 || e.KeyCode == Keys.NumPad6) { button6_Click(null, null); } else if (e.KeyCode == Keys.D7 || e.KeyCode == Keys.NumPad7) { button7_Click(null, null); } else if (e.KeyCode == Keys.D8 || e.KeyCode == Keys.NumPad8) { button8_Click(null, null); } else if (e.KeyCode == Keys.D9 || e.KeyCode == Keys.NumPad9) { button9_Click(null, null); } else if (e.KeyCode == Keys.D0 || e.KeyCode == Keys.NumPad0) { button10_Click(null, null); } } private void textBox1_Enter(object sender, EventArgs e) { label1.Focus(); } } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.