C#制作简易计算器
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
using System;
using System.Collections.Generic;
using ponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace MyCalculater
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
bool isDotpressed = false;
int iOperator;
float dOperand1;
float dOperand2;
float dResult;
private void textBox1_TextChanged(object sender, EventArgs e) {
}
private void版权说明ToolStripMenuItem_Click(object sender, EventArgs e) {
Form2 newForm = new Form2();
newForm.Show();
}//这一部分是版权说明,可有可无
private void bt1_Click(object sender, EventArgs e)
{
tbResult.Text = tbResult.Text + "1";
}
private void bt2_Click(object sender, EventArgs e)
{
tbResult.Text = tbResult.Text + "2";
}
private void bt3_Click(object sender, EventArgs e)
{
tbResult.Text = tbResult.Text + "3";
}
private void bt4_Click(object sender, EventArgs e)
{
tbResult.Text = tbResult.Text + "4";
}
private void bt5_Click(object sender, EventArgs e)
{
tbResult.Text = tbResult.Text + "5";
}
private void bt6_Click(object sender, EventArgs e)
{
tbResult.Text = tbResult.Text + "6";
}
private void bt7_Click(object sender, EventArgs e)
{
tbResult.Text = tbResult.Text + "7";
}
private void bt8_Click(object sender, EventArgs e)
{
tbResult.Text = tbResult.Text + "8";
}
private void bt9_Click(object sender, EventArgs e)
{
tbResult.Text = tbResult.Text + "9";
}
private void bt0_Click(object sender, EventArgs e)
{
if (tbResult.Text.Length != 0)
{
tbResult.Text = tbResult.Text + "0";
}
}
private void btDot_Click(object sender, EventArgs e) {
if (!isDotpressed)
{
tbResult.Text = tbResult.Text + ".";
isDotpressed = true;
}
}
private void btClear_Click(object sender, EventArgs e) {
tbResult.Text = "";
}
private void btAdd_Click(object sender, EventArgs e) {
if (tbResult.Text.Length != 0)
{
dOperand1 = float.Parse(tbResult.Text);
}
else
{
dOperand1 = 0;
}
iOperator = 1;
tbResult.Text = "";
isDotpressed = false;
}
private void btSub_Click(object sender, EventArgs e) {
if (tbResult.Text.Length != 0)
{
dOperand1 = float.Parse(tbResult.Text);
}
else
{
dOperand1 = 0;
}
iOperator = 2;
tbResult.Text = "";
isDotpressed = false;
}
private void btMul_Click(object sender, EventArgs e) {
if (tbResult.Text.Length != 0)
{
dOperand1 = float.Parse(tbResult.Text);
}
else
{
dOperand1 = 0;
}
iOperator = 3;
tbResult.Text = "";
isDotpressed = false;
}
private void btDiv_Click(object sender, EventArgs e) {
if (tbResult.Text.Length != 0)
{
dOperand1 = float.Parse(tbResult.Text);
}
else
{
dOperand1 = 0;
}
iOperator = 4;
tbResult.Text = "";
isDotpressed = false;
}