基本信息
源码名称:C# 计算器(加减乘除、乘方等功能)
源码大小:0.06M
文件格式:.zip
开发语言:C#
更新时间:2021-11-21
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 1 元×
微信扫码支付:1 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
普通计算器,可以实现乘方等功能
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 计算器
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string str, fh;
double num1, num2, num3, result;
private void number(object sender, EventArgs e)
{
Button b = (Button)(sender);
str = b.Text;
if (textBox1.Text == "0")
{
textBox1.Text = str;
}
else
{
textBox1.Text = textBox1.Text str;
}
}
private void button24_Click(object sender, EventArgs e)
{
Close();
}
private void SiZe(object sender, EventArgs e)
{
Button btn = (Button)(sender);
if (btn.Text ==" ")
{
num1 = double.Parse(textBox1.Text);
textBox1.Text = "";
fh = " ";
}
else if (btn.Text == "-")
{
num1 = double.Parse(textBox1.Text);
textBox1.Text = "";
fh = "-";
}
else if (btn.Text == "*")
{
num1 = double.Parse(textBox1.Text);
textBox1.Text = "";
fh = "*";
}
else if (btn.Text == "/")
{
num1 = double.Parse(textBox1.Text);
textBox1.Text = "";
fh = "/";
}
else if (btn.Text=="=")
{
num2 = double.Parse(textBox1.Text);
if (fh==" ")
{
num3 = num1 num2;
textBox1.Text = num3.ToString();
}
else if (fh=="-")
{
num3 = num1 - num2;
textBox1.Text = num3.ToString();
}
else if (fh == "*")
{
num3 = num1 * num2;
textBox1.Text = num3.ToString();
}
else if (fh == "/")
{
num3 = num1 / num2;
textBox1.Text = num3.ToString();
}
}
}
private void gongneng(object sender, EventArgs e)
{
Button btn = (Button)(sender);
if (btn.Text == "<--退格")
{
if (textBox1.Text != "")
{
str = textBox1.Text;
str = str.Substring(0, str.Length - 1);
textBox1.Text = str;
}
}
else if (btn.Text == ".")
{
str = textBox1.Text;
int index = str.IndexOf(".");
if (index == -1)
{
textBox1.Text = str ".";
}
}
else if (btn.Text == "sqrt")
{
num1 = double.Parse(textBox1.Text);
result = Math.Sqrt(num1);
textBox1.Text = result.ToString();
}
else if (btn.Text == "C")
{
num1 = num2 = result = num3 = 0;
str = null;
fh = null;
textBox1.Text = "0";
}
else if (btn.Text == "CE")
{
textBox1.Text = "0";
}
else if (btn.Text == " /-")
{
num1 = double.Parse(textBox1.Text);
result = num1 * -1;
textBox1.Text = result.ToString();
}
else if (btn.Text == "%")
{
num1 = double.Parse(textBox1.Text);
result = num1 / 100;
textBox1.Text = result.ToString();
}
else if (btn.Text == "1/x")
{
num1 = double.Parse(textBox1.Text);
result = 1 / num1;
textBox1.Text = result.ToString();
}
}
}
}
普通计算器,可以实现乘方等功能
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 计算器
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string str, fh;
double num1, num2, num3, result;
private void number(object sender, EventArgs e)
{
Button b = (Button)(sender);
str = b.Text;
if (textBox1.Text == "0")
{
textBox1.Text = str;
}
else
{
textBox1.Text = textBox1.Text str;
}
}
private void button24_Click(object sender, EventArgs e)
{
Close();
}
private void SiZe(object sender, EventArgs e)
{
Button btn = (Button)(sender);
if (btn.Text ==" ")
{
num1 = double.Parse(textBox1.Text);
textBox1.Text = "";
fh = " ";
}
else if (btn.Text == "-")
{
num1 = double.Parse(textBox1.Text);
textBox1.Text = "";
fh = "-";
}
else if (btn.Text == "*")
{
num1 = double.Parse(textBox1.Text);
textBox1.Text = "";
fh = "*";
}
else if (btn.Text == "/")
{
num1 = double.Parse(textBox1.Text);
textBox1.Text = "";
fh = "/";
}
else if (btn.Text=="=")
{
num2 = double.Parse(textBox1.Text);
if (fh==" ")
{
num3 = num1 num2;
textBox1.Text = num3.ToString();
}
else if (fh=="-")
{
num3 = num1 - num2;
textBox1.Text = num3.ToString();
}
else if (fh == "*")
{
num3 = num1 * num2;
textBox1.Text = num3.ToString();
}
else if (fh == "/")
{
num3 = num1 / num2;
textBox1.Text = num3.ToString();
}
}
}
private void gongneng(object sender, EventArgs e)
{
Button btn = (Button)(sender);
if (btn.Text == "<--退格")
{
if (textBox1.Text != "")
{
str = textBox1.Text;
str = str.Substring(0, str.Length - 1);
textBox1.Text = str;
}
}
else if (btn.Text == ".")
{
str = textBox1.Text;
int index = str.IndexOf(".");
if (index == -1)
{
textBox1.Text = str ".";
}
}
else if (btn.Text == "sqrt")
{
num1 = double.Parse(textBox1.Text);
result = Math.Sqrt(num1);
textBox1.Text = result.ToString();
}
else if (btn.Text == "C")
{
num1 = num2 = result = num3 = 0;
str = null;
fh = null;
textBox1.Text = "0";
}
else if (btn.Text == "CE")
{
textBox1.Text = "0";
}
else if (btn.Text == " /-")
{
num1 = double.Parse(textBox1.Text);
result = num1 * -1;
textBox1.Text = result.ToString();
}
else if (btn.Text == "%")
{
num1 = double.Parse(textBox1.Text);
result = num1 / 100;
textBox1.Text = result.ToString();
}
else if (btn.Text == "1/x")
{
num1 = double.Parse(textBox1.Text);
result = 1 / num1;
textBox1.Text = result.ToString();
}
}
}
}