《用visual studio制作的简单的计算器(8页).doc》由会员分享,可在线阅读,更多相关《用visual studio制作的简单的计算器(8页).doc(8页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、-用visual studio制作的简单的计算器。-第 8 页首先利用visual studio里面的button和textbox模块建立上图模块。然后就是编写程序:该程序最重要的是要理解清楚计算器的运算逻辑。public partial class Form1 : Form string a, b, q, ac; int c = 0, d = 0, n = 0, p = 0, m = 0; double temp1 = -1; int pos = 0; public Form1() InitializeComponent(); private void textBox1_TextChange
2、d(object sender, EventArgs e) public void addNum(int num) textBox1.Text = textBox1.Text + num.ToString(); if (c 0) / 管理加减?乘?除y运?算? textBox1.Text = ; a = num.ToString(); b = b + a; textBox1.Text = b; private void button1_Click(object sender, EventArgs e) addNum(7); /向显?示?屏加字? n+; private void button2
3、_Click(object sender, EventArgs e) addNum(8); private void button3_Click(object sender, EventArgs e) addNum(9); private void button5_Click(object sender, EventArgs e) addNum(4); private void button6_Click(object sender, EventArgs e) addNum(5); private void button7_Click(object sender, EventArgs e) a
4、ddNum(6); private void button9_Click(object sender, EventArgs e) addNum(1); private void button10_Click(object sender, EventArgs e) addNum(2); private void button11_Click(object sender, EventArgs e) addNum(3); private void button14_Click(object sender, EventArgs e) addNum(0); private void button15_C
5、lick(object sender, EventArgs e) if (p=0) textBox1.Text = textBox1.Text + .;/加上?小?数y点? p+; m+; if (c 0) / 管理加减?乘?除y运?算? b = b + .; private void button4_Click(object sender, EventArgs e) pos = 1; temp1 = Convert .ToDouble (textBox1.Text); textBox1.Text =temp1+; d+; c+; p = 0; private void button8_Cli
6、ck(object sender, EventArgs e) pos = 2; temp1 = Convert.ToDouble(textBox1.Text); textBox1.Text = temp1 + -; c+; p = 0; private void button12_Click(object sender, EventArgs e) pos = 3; temp1 = Convert.ToDouble(textBox1.Text); textBox1.Text = temp1 + *; c+; p = 0; private void button16_Click(object se
7、nder, EventArgs e) pos = 4; temp1 = Convert.ToDouble(textBox1.Text); textBox1.Text = temp1 + /; c+; p = 0; private void button13_Click(object sender, EventArgs e) double temp2 = Convert.ToDouble(b); switch (pos) case 1: textBox1.Text = (temp1 + temp2).ToString(); break; case 2: textBox1.Text = (temp1 - temp2).ToString(); break; case 3: textBox1.Text = (temp1 * temp2).ToString(); break; case 4: textBox1.Text = (temp1 / temp2).ToString(); break; private void button17_Click(object sender, EventArgs e) textBox1.Text = ;/清?空?显?示?器 temp1 = 0; pos = 0; b = ; a = ; n = 0; c = 0; p = 0;
限制150内