# C#||应用框体设计计算器

#### 示例代码：

using System;
using System.Windows.Forms;
namespace Calculator
{
public partial class FormMain : Form
{
double number1 = 0,number2 = 0,result;
int inputnumber;
enum Operator { none,plus,minus,multiplication,division}
Operator mode = Operator.none;
bool isequal = false;
public FormMain()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
inputnumber =4;
call(inputnumber);
}
private void button4_Click(object sender, EventArgs e)
{
inputnumber = 1;
call(inputnumber);
}
private void button16_Click(object sender, EventArgs e)
{
inputnumber = 9;
call(inputnumber);
}
private void button2_Click(object sender, EventArgs e)
{
inputnumber = 5;
call(inputnumber);
}
private void button3_Click(object sender, EventArgs e)
{
inputnumber = 6;
call(inputnumber);
}
private void button5_Click(object sender, EventArgs e)
{
inputnumber =2;
call(inputnumber);
}
private void button6_Click(object sender, EventArgs e)
{
inputnumber =3;
call(inputnumber);
}
private void button7_Click(object sender, EventArgs e)
{
inputnumber = 0;
call(inputnumber);
}
private void button12_Click(object sender, EventArgs e)
{
mode = Operator.plus;
switchmode();
}
private void button11_Click(object sender, EventArgs e)
{
mode = Operator.minus;
switchmode();
}
private void button10_Click(object sender, EventArgs e)
{
mode = Operator.multiplication;
switchmode();
}
private void button9_Click(object sender, EventArgs e)
{
mode = Operator.division;
switchmode();
}
private void button8_Click(object sender, EventArgs e)
{
switch (mode)
{
case Operator.plus:
result = number1 + number2;
break;
case Operator.minus:
result = number1 - number2;
break;
case Operator.multiplication:
result = number1 * number2;
break;
case Operator.division:
result = number1 / number2;
break;
}
number1 = 0;
number2 = 0;
isequal = true;
labelbefore.Text = " ";
labelmode.Text = " ";
labelout.Text = Convert.ToString(result);
}
private void button14_Click(object sender, EventArgs e)
{
inputnumber = 8;
call(inputnumber);
}
private void button13_Click(object sender, EventArgs e)
{
inputnumber = 7;
call(inputnumber);
}
private void button15_Click(object sender, EventArgs e)
{
cleanall();
}
public void call(int an)
{
if (mode == Operator.none)
{
number1 = number1 * 10 + an;
labelout.Text = Convert.ToString(number1);
}
else
{
number2 = number2 * 10 + an;
labelout.Text = Convert.ToString(number2);
}
}
private void labelout_Click(object sender, EventArgs e)
{
labelout.Text = Convert.ToString(number1);
}
public void cleanall()
{
number1 = 0;
number2 = 0;
labelout.Text = Convert.ToString(number1);
labelbefore.Text = " ";
labelmode.Text = " ";
isequal = false;
mode = Operator.none;
}
public void switchmode()
{
switch (mode)
{
case Operator.plus:
labelmode.Text = "+";
break;
case Operator.minus:
labelmode.Text = "-";
break;
case Operator.multiplication:
labelmode.Text = "x";
break;
case Operator.division:
labelmode.Text = "/";
break;
}
if(isequal == true)
{
number1 = result;
}
labelbefore.Text = Convert.ToString(number1);
labelout.Text = Convert.ToString(number2);

}
}
}

#### 测试：

|
1月前
|

LIMS（实验室）信息管理系统源码、有哪些应用领域？采用C# ASP.NET dotnet 3.5 开发的一套实验室信息系统源码

36 3
|
2月前
|

PACS的功能价值在于通过连接不同的影像设备，存储与管理图像，图像的调用与后处理，实现资源共享，降低成本，达到提高工作效率、提升医疗水平的目地；
35 1
|
2月前
|

138 3
|
2月前
|

C# GetField 方法应用实例
C# GetField 方法应用实例
37 2
|
2月前
|
JSON 安全 API
C# GetMethod 方法应用实例
C# GetMethod 方法应用实例
32 2
|
2月前
|

C#编程的跨平台应用
【4月更文挑战第21天】C#与.NET Core的结合使得跨平台应用开发变得高效便捷，提供统一编程模型和高性能。丰富的类库、活跃的社区支持及Visual Studio Code、Xamarin等工具强化了其优势。广泛应用在企业系统、云服务和游戏开发中，虽面临挑战，但随着技术进步，C#在跨平台开发领域的前景广阔。
178 2
|
2月前
|
SQL 开发框架 .NET
C#linq表达式的应用
C#linq表达式的应用
19 0
|
10月前
|

C#之二十二 WIN应用程序的安装部署
C#之二十二 WIN应用程序的安装部署
47 0
|
2月前
|

C# 面向对象编程进阶：构造函数详解与访问修饰符应用

53 1
|
2月前
|
C#
C# 运算符详解：包含算术、赋值、比较、逻辑运算符及 Math 类应用

57 1