教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 文库大全 > 实用文档 >

c#超详细计算器代码

来源:网络收集 时间:2026-09-11
导读: c#简易计算器源代码! C#超详细计算器源代码 using System; using System.Collections.Generic; using ponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.F

c#简易计算器源代码!

C#超详细计算器源代码

using System;

using System.Collections.Generic;

using ponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

namespace 计算器

{

public partial class Form1 : Form

{

int flag = 0;

double num1 = 0, num2 = 0;

int ysf = 0, dh = 0, yscs = 0;

public Form1()

{

InitializeComponent();

}

c#简易计算器源代码!

{

if (textBox1.Text == "0" || flag == 1)

{

textBox1.Text = "1"; flag = 0;

}

else

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

}

private void button2_Click(object sender, EventArgs e)

{

if (textBox1.Text == "0" || flag == 1)

{

textBox1.Text = "2"; flag = 0;

}

else

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

button16.Focus();

}

private void button3_Click(object sender, EventArgs e)

{

if (textBox1.Text == "0" || flag == 1)

{

textBox1.Text = "3"; flag = 0;

}

else

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

button16.Focus();

}

private void button4_Click(object sender, EventArgs e)

{

if (textBox1.Text == "0" || flag == 1)

{

textBox1.Text = "4"; flag = 0;

}

else

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

button16.Focus();

}

c#简易计算器源代码!

{

if (textBox1.Text == "0" || flag == 1)

{

textBox1.Text = "5"; flag = 0;

}

else

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

button16.Focus();

}

private void button6_Click(object sender, EventArgs e)

{

if (textBox1.Text == "0" || flag == 1)

{

textBox1.Text = "6"; flag = 0;

}

else

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

button16.Focus();

}

private void button7_Click(object sender, EventArgs e)

{

if (textBox1.Text == "0" || flag == 1)

{

textBox1.Text = "7"; flag = 0;

}

else

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

button16.Focus();

}

private void button8_Click(object sender, EventArgs e)

{

if (textBox1.Text == "0" || flag == 1)

{

textBox1.Text = "8"; flag = 0;

}

else

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

button16.Focus();

}

c#简易计算器源代码!

{

if (textBox1.Text == "0" || flag == 1)

{

textBox1.Text = "9"; flag = 0;

}

else

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

button16.Focus();

}

private void button10_Click(object sender, EventArgs e)

{

if (textBox1.Text == "0." || flag == 1)

{

textBox1.Text = "0"; flag = 0;

}

else

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

button16.Focus();

}

private void button12_Click(object sender, EventArgs e)

{

flag = 1;

dh = 0;

yscs++;

num2 = Convert.ToDouble(textBox1.Text);

switch (ysf)

{

case 1: textBox1.Text = (num1 + num2).ToString(); break; case 2: textBox1.Text = (num1 - num2).ToString(); break; case 3: textBox1.Text = (num1 * num2).ToString(); break; case 4: if (num2 == 0)

{

MessageBox.Show("分母不能为0");

}

textBox1.Text = (num1 / num2).ToString(); break;

}

ysf = 1;

num1 = Convert.ToDouble(textBox1.Text);

button16.Focus();

c#简易计算器源代码!

}

private void button13_Click(object sender, EventArgs e)

{

flag = 1;

dh = 0;

yscs++;

num2 = Convert.ToDouble(textBox1.Text);

switch (ysf)

{

case 1: textBox1.Text = (num1 + num2).ToString(); break; case 2: textBox1.Text = (num1 - num2).ToString(); break; case 3: textBox1.Text = (num1 * num2).ToString(); break; case 4: if (num2 == 0) {

MessageBox.Show("分母不能为0");

}

textBox1.Text = (num1 / num2).ToString(); break;

}

ysf = 2;

num1 = Convert.ToDouble(textBox1.Text);

button16.Focus();

}

private void button14_Click(object sender, EventArgs e)

{

flag = 1;

dh = 0;

yscs++;

num2 = Convert.ToDouble(textBox1.Text);

switch (ysf)

{

case 1: textBox1.Text = (num1 + num2).ToString(); break; case 2: textBox1.Text = (num1 - num2).ToString(); break; case 3: textBox1.Text = (num1 * num2).ToString(); break; case 4: if (num2 == 0)

{

MessageBox.Show("分母不能为0");

}

textBox1.Text = (num1 / num2).ToString(); break;

c#简易计算器源代码!

}

ysf = 3;

num1 = Convert.ToDouble(textBox1.Text);

button16.Focus();

}

private void button15_Click(object sender, EventArgs e)

{

flag = 1;

dh = 0;

yscs++;

num2 = Convert.ToDouble(textBox1.Text);

switch (ysf)

{

case 1: textBox1.Text = (num1 + num2).ToString(); break; case 2: textBox1.Text = (num1 - num2).ToString(); break; case 3: textBox1.Text = (num1 * num2).ToString(); break; case 4: if (num2 == 0) {

MessageBox.Show("分母不能为0");

}

textBox1.Text = (num1 / nu …… 此处隐藏:3935字,全部文档内容请下载后查看。喜欢就下载吧 ……

c#超详细计算器代码.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wenku/136461.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)