c#计算机代码,C#计算器源代码

满意答案

dcebd7a0de6265b6ccae5ead692f1eab.png

Vh3yQT1

2013.06.01

dcebd7a0de6265b6ccae5ead692f1eab.png

采纳率:50%    等级:11

已帮助:5291人

using System;

using System.Collections.Generic;

using System.Drawing;

using System.Windows.Forms;namespace windshadow14

{

public partial class MainForm

{

int i =0;

int a ;

int b;

int i1;

long c;

public static void Main(string[] args)

{

Application.EnableVisualStyles();

Application.SetCompatibleTextRenderingDefault(false);

Application.Run(new MainForm());

}

public MainForm()

{

InitializeComponent();

}

void Button10Click(object sender, System.EventArgs e)

{

if(textBox1.Text ==" ")

{

textBox1.Text =textBox1.Text+"0";

}

}

void Button1Click(object sender, System.EventArgs e)

{

textBox1.Text =textBox1.Text+"1";

if(textBox1.Text==" ")

{

textBox1.Text =textBox1.Text+"1";

}

}

void Button2Click(object sender, System.EventArgs e)

{

textBox1.Text =textBox1.Text+"2";

if(textBox1.Text==" ")

{

textBox1.Text =textBox1.Text+"2";

}

}

void Button3Click(object sender, System.EventArgs e)

{

textBox1.Text =textBox1.Text+"3";

if(textBox1.Text ==" ")

{

textBox1.Text =textBox1.Text+"3";

}

}

void Button4Click(object sender, System.EventArgs e)

{

textBox1.Text =textBox1.Text+"4";

if(textBox1.Text==" ")

{

textBox1.Text =textBox1.Text+"4";

}

}

void Button5Click(object sender, System.EventArgs e)

{

textBox1.Text =textBox1.Text+"5";

if(textBox1.Text ==" ")

{

textBox1.Text =textBox1.Text+"5";

}

}

void Button6Click(object sender, System.EventArgs e)

{

textBox1.Text =textBox1.Text+"6";

if(textBox1.Text==" ")

{

textBox1.Text =textBox1.Text+"6";

}

}

void Button7Click(object sender, System.EventArgs e)

{

textBox1.Text =textBox1.Text+"7";

if(textBox1.Text ==" ")

{

textBox1.Text =textBox1.Text+"7";

}

}

void Button8Click(object sender, System.EventArgs e)

{

textBox1.Text =textBox1.Text+"8";

if(textBox1.Text ==" ")

{

textBox1.Text =textBox1.Text+"8";

}

}

void Button9Click(object sender, System.EventArgs e)

{

textBox1.Text =textBox1.Text+"9";

if(textBox1.Text ==" ")

{

textBox1.Text =textBox1.Text+"9";

}

}

void TextBox1TextChanged(object sender, System.EventArgs e)

{

if(i==1||i==2||i==3||i==4)

{

textBox1.Text =" ";

}

i=0;

}

void Button12Click(object sender, System.EventArgs e)

{

i=1;

a =int .Parse (textBox1.Text);

i1=1;

}

void Button16Click(object sender, System.EventArgs e)

{

b=int.Parse (textBox1.Text );

textBox1.Text =" ";

switch(i1)

{

case 1:

c =a +b ;

break ;

case 2:

c =a -b ;

break;

case 3:

c =a *b ;

break;

case 4:

c =a /b ;

break;

}

textBox1.Text =c.ToString ();

i=0;

a=0;

b=0;

i1=0;

}

void Button13Click(object sender, System.EventArgs e)

{

i1=2;

i=1;

a =int .Parse (textBox1.Text);

}

void MainFormLoad(object sender, System.EventArgs e)

{

}

void Button14Click(object sender, System.EventArgs e)

{

i1=3;

i=3;

a =int .Parse (textBox1.Text);

}

void Button15Click(object sender, System.EventArgs e)

{

i1=4;

i=4;

a =int .Parse (textBox1.Text);

}

}

}

还可以这样编 using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;namespace windshadow

{

public partial class Form1 : Form

{

int a;

int b;

int c;

int b1;

public Form1()

{

InitializeComponent();

}private void button1_Click(object sender, EventArgs e)

{

textBox1.Text = textBox1.Text + "1";

if (b == 1)

{

textBox1.Text = "";textBox1.Text = textBox1.Text + "1";

b = 0;}}private void button2_Click(object sender, EventArgs e)

{

textBox1.Text = textBox1.Text + "2";

if (b == 1)

{

textBox1.Text = "";textBox1.Text = textBox1.Text + "2";

b = 0;}

}private void button3_Click(object sender, EventArgs e)

{

textBox1.Text = textBox1.Text + "3";

if (b == 1)

{

textBox1.Text = "";textBox1.Text = textBox1.Text + "3";

b = 0;}

}private void button4_Click(object sender, EventArgs e)

{

textBox1.Text = textBox1.Text + "4";

if (b == 1)

{

textBox1.Text = "";textBox1.Text = textBox1.Text + "4";

b = 0;}

}private void button5_Click(object sender, EventArgs e)

{

textBox1.Text = textBox1.Text + "5";

if (b == 1)

{

textBox1.Text = "";textBox1.Text = textBox1.Text + "5";

b = 0;}

}private void button6_Click(object sender, EventArgs e)

{

textBox1.Text = textBox1.Text + "6";

if (b == 1)

{

textBox1.Text = "";textBox1.Text = textBox1.Text + "6";

b = 0;}

}private void button7_Click(object sender, EventArgs e)

{

textBox1.Text = textBox1.Text + "7";

if (b == 1)

{

textBox1.Text = "";textBox1.Text = textBox1.Text + "7";

b = 0;}

}private void button8_Click(object sender, EventArgs e)

{

textBox1.Text = textBox1.Text + "8";

if (b == 1)

{

textBox1.Text = "";textBox1.Text = textBox1.Text + "8";

b = 0;}

}private void button9_Click(object sender, EventArgs e)

{

textBox1.Text = textBox1.Text + "9";

if (b == 1)

{

textBox1.Text = "";textBox1.Text = textBox1.Text + "9";

b = 0;}

}private void button11_Click(object sender, EventArgs e)

{

textBox1.Text = textBox1.Text + "0";

if (b == 1)

{

textBox1.Text = "";textBox1.Text = textBox1.Text + "0";

b = 0;}

}private void button10_Click(object sender, EventArgs e)

{

textBox1.Text = textBox1.Text + ".";

}private void button13_Click(object sender, EventArgs e)

{

a = int.Parse (textBox1.Text);

b = 1;

b1 = 1;

}private void button17_Click(object sender, EventArgs e)

{

long d;

switch (b1)

{

case 1:c = int.Parse(textBox1.Text);

d = a + c;

textBox1.Text = "";

textBox1.Text = d.ToString();

break;

case 2:

c = int.Parse(textBox1.Text);

d = a - c;

textBox1.Text = "";

textBox1.Text = d.ToString();

break;

case 3:

c = int.Parse(textBox1.Text);

d = a * c;

textBox1.Text = "";

textBox1.Text = d.ToString();

break;

case 4:

c = int.Parse(textBox1.Text);

d = a / c;

textBox1.Text = "";

textBox1.Text = d.ToString();

break;

}

}private void button14_Click(object sender, EventArgs e)

{

a = int.Parse(textBox1.Text);b = 1;

b1 = 2;

}private void button15_Click(object sender, EventArgs e)

{

a = int.Parse(textBox1.Text);b = 1;

b1 = 3;

}private void button16_Click(object sender, EventArgs e)

{

a = int.Parse(textBox1.Text);b = 1;

b1 = 4;

}private void button12_Click(object sender, EventArgs e)

{

textBox1.Text = "";

b = 0;

b1 = 0;

a = 0;

c = 0;

}private void textBox1_TextChanged(object sender, EventArgs e)

{

}

}

}这是退格键void Button1Click(object sender, System.EventArgs e)

{

try

{

int a =int .Parse (textBox1.Text);

a =a/10;

textBox1.Text =a.ToString ();

}

catch

{

double a =double.Parse (textBox1.Text );

int b = (int)a;

textBox1.Text =a.ToString ();

int zz =textBox1.Text.Length ;

int t = zz-1;

textBox1.Text=textBox1.Text.Remove(t);

}

}

40分享举报

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值