close

程式設計工藝大師:http://tccnchsu.blogspot.tw/

000  

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace _1
{
public partial class Form1 : Form
{
int a = 0, b = 0,i=4;
float a1 = 0, b1 = 0, c1 = 1;
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
textBox2.Text ="+";
if (a == 0) {
a = 1;
textBox2.Visible = true;
textBox3.Visible = true;
b = 0;
button17.Enabled = true;
c1 = 1;
}
i = 0;
}

private void button2_Click(object sender, EventArgs e)
{
textBox2.Text ="-";
if (a == 0)
{
a = 1;
textBox2.Visible = true;
textBox3.Visible = true;
b = 0;
button17.Enabled = true;
c1 = 1;
}
i = 1;
}

private void button3_Click(object sender, EventArgs e)
{
textBox2.Text ="*";
if (a == 0)
{
a = 1;
textBox2.Visible = true;
textBox3.Visible = true;
b = 0;
button17.Enabled = true;
c1 = 1;
}
i = 2;
}

private void button4_Click(object sender, EventArgs e)
{
textBox2.Text ="/";
if (a == 0)
{
a = 1;
textBox2.Visible = true;
textBox3.Visible = true;
b = 0;
button17.Enabled = true;
c1 = 1;
}
i = 3;
}
private void button5_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
a = 0;
b = 0;
a1 = 0;
b1 = 0;
c1 = 1;
i = 4;
textBox2.Visible = false;
textBox3.Visible = false;
textBox4.Visible = false;
button17.Enabled = true;
}

private void button8_Click(object sender, EventArgs e)
{
add(1);
}

private void button9_Click(object sender, EventArgs e)
{
add(2);
}

private void button10_Click(object sender, EventArgs e)
{
add(3);
}

private void button11_Click(object sender, EventArgs e)
{
add(4);
}

private void button12_Click(object sender, EventArgs e)
{
add(5);
}

private void button13_Click(object sender, EventArgs e)
{
add(6);
}

private void button14_Click(object sender, EventArgs e)
{
add(7);
}

private void button15_Click(object sender, EventArgs e)
{
add(8);
}

private void button16_Click(object sender, EventArgs e)
{
add(9);
}

private void button17_Click(object sender, EventArgs e)
{
b = 1;
button17.Enabled = false;
if (a == 0) { textBox1.Text = textBox1.Text + "."; }
if (a == 1)
{
textBox3.Text = textBox3.Text + ".";
}
}

private void button7_Click(object sender, EventArgs e)
{
textBox4.Visible = true;
if (i == 0)
{
c1=a1+b1;
textBox4.Text = ""+c1;
}
if (i == 1)
{
c1 = a1 - b1;
textBox4.Text = "" + c1;
}
if (i == 2)
{
c1 = a1 * b1;
textBox4.Text = "" + c1;
}
if (i == 3)
{
if (b1 != 0)
{
c1 = a1 / b1;
textBox4.Text = "" + c1;
}
else if (b1 == 0) { textBox4.Text = "error!"; }
}
}

private void add(int i)
{
if (a == 0)
{
textBox1.Text = textBox1.Text +i;
if (b == 0)
{
a1 = a1 * 10 + i;
}
if (b == 1)
{
c1 = c1 / 10;
a1 = a1 + i * c1;
}
}
if (a == 1)
{
textBox3.Text = textBox3.Text+i ;
if (b == 0)
{
b1 = b1 * 10 + i;
}
if (b == 1)
{
c1 = c1 / 10;
b1 = b1 + i * c1;
}
}
}

private void button6_Click(object sender, EventArgs e)
{
add(0);
}
}
}

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 fwcgex1529 的頭像
    fwcgex1529

    fwcgex1529的部落格

    fwcgex1529 發表在 痞客邦 留言(0) 人氣()