这篇文章主要为大家详细介绍了C#实现简易计算器,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了C#实现简易计算器功能的具体代码,供大家参考,具体内容如下
实现页面布局和数值初始化
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsAppCalculator
{
public partial class Form1 : Form
{
double number = 0;
public Form1()
{
InitializeComponent();
}
private void num1_Click(object sender, EventArgs e)
{
number = number * 10 + 1;
labelout.Text = Convert.ToString(number);
}
private void num2_Click(object sender, EventArgs e)
{
number = number * 10 + 2;
labelout.Text = Convert.ToString(number);
}
private void num3_Click(object sender, EventArgs e)
{
number = number * 10 + 3;
labelout.Text = Convert.ToString(number);
}
private void num4_Click(object sender, EventArgs e)
{
number = number * 10 + 4;
labelout.Text = Convert.ToString(number);
}
private void num5_Click(object sender, EventArgs e)
{
number = number * 10 + 5;
labelout.Text = Convert.ToString(number);
}
private void num6_Click(object sender, EventArgs e)
{
number = number * 10 + 6;
labelout.Text = Convert.ToString(number);
}
private void num7_Click(object sender, EventArgs e)
{
number = number * 10 + 7;
labelout.Text = Convert.ToString(number);
}
private void num8_Click(object sender, EventArgs e)
{
number = number * 10 + 8;
labelout.Text = Convert.ToString(number);
}
private void num9_Click(object sender, EventArgs e)
{
number = number * 10 + 9;
labelout.Text = Convert.ToString(number);
}
private void num0_Click(object sender, EventArgs e)
{
number = number * 10 + 0;
labelout.Text = Convert.ToString(number);
}
private void Form1_Load(object sender, EventArgs e)
{
labelout.Text = Convert.ToString(number);
}
private void clean_Click(object sender, EventArgs e)
{
number = 0;
labelout.Text = Convert.ToString(number);
}
}
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持得得之家。
沃梦达教程
本文标题为:C#实现简易计算器功能(1)(窗体应用)
基础教程推荐
猜你喜欢
- C# windows语音识别与朗读实例 2023-04-27
- unity实现动态排行榜 2023-04-27
- C# 调用WebService的方法 2023-03-09
- C#控制台实现飞行棋小游戏 2023-04-22
- C# List实现行转列的通用方案 2022-11-02
- linux – 如何在Debian Jessie中安装dotnet core sdk 2023-09-26
- ZooKeeper的安装及部署教程 2023-01-22
- 一个读写csv文件的C#类 2022-11-06
- winform把Office转成PDF文件 2023-06-14
- C#类和结构详解 2023-05-30