C#实现简易计算器功能(1)(窗体应用)
短信预约 -IT技能 免费直播动态提醒
本文实例为大家分享了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);
}
}
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程网。
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341