C#计算器源代码

哪位大哥有用C#语言写的窗体应用程序计算器的源代码。类似于Windows自带的计算器。要用到BUTTON点击实现数字输入和加减乘除。。... 哪位大哥有用C#语言写的窗体应用程序计算器的源代码。类似于Windows自带的计算器。要用到BUTTON点击实现数字输入和加减乘除。。 展开
 我来答
匿名用户
推荐于2017-06-01
展开全部
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);

}

}
AiPPT
2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图... 点击进入详情页
本回答由AiPPT提供
匿名用户
2013-06-23
展开全部
我记得 微软 在 visual studio 2005中 有使用 visual j# 做了一个初学者 包 .就是 用 visual j#开发了一个科学计数器.使用C#做了一个屏保程序.使用VB.NET做了一个 唱片收藏软件. 在我念书的时候 有研究这个代码.收益颇深啊. 你可以去搜索一下 这些程序. 这里你要的是 计数器源代码,就找这里 visual J# 做的这个计数器.然后 使用 反编译 程序 .NET Reference 输出 C# 就是了. 这个计数器可是和 操作系统里面的功能一模一样喔;.这里强调的是 学习人家的代码,.而不是 应付老师喔 :)
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2013-06-23
展开全部
535944903 加我QQ 我给你源代码 保证你满意
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式