用visual studio制作的简单的计算器(8页).doc
-用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_TextChanged(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_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) addNum(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_Click(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_Click(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 sender, 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;