一、计算器

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace _4计算器
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button8_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + button8.Text;
} private void button11_Click(object sender, EventArgs e)
{
double r;//用于保存结果
string t = textBox1.Text;//用以保存文本框中的算术表达式
int space = t.IndexOf(' ');//用以搜索文本框中的空格位置,注意是位置
string s1 = t.Substring(0, space);//s1用于保存第一个运算数
char op = Convert.ToChar(t.Substring(space + 1, 1));//op用以保存运算符
string s2 = t.Substring(space+3);//s2用于保存第二个运算数
double arg1 = Convert.ToDouble(s1);//将运算数从string转换成double
double arg2 = Convert.ToDouble(s2);
switch (op)
{
case '+':
r = arg1 + arg2;
break;
case '-':
r = arg1 - arg2;
break;
case '*':
r = arg1 * arg2;
break;
case '/':
if (arg2 == 0)
{
// MessageBox.Show("0不能做分母","错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
throw new ApplicationException();
}
else
{
r = arg1 / arg2;
break; //跳出if语句
}
break; //这是case'/'的break,跳出switch
default:
throw new ApplicationException();
}
textBox1.Text = r.ToString();
} private void button1_Click(object sender, EventArgs e)
{
// Button btn = (Button)sender;
// textBox1.Text = textBox1.Text + btn.Text;
textBox1.Text = textBox1.Text + button1.Text;
} private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + button2.Text;
} private void button3_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + button3.Text;
} private void button6_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + button6.Text;
} private void button5_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + button5.Text;
} private void button4_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + button4.Text;
} private void button9_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + button9.Text;
} private void button7_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + button7.Text;
} private void button12_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + button12.Text;
} private void button14_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + " "+button14.Text+" ";
} private void button13_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + " " + button13.Text + " ";
} private void button10_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + " " + button10.Text + " ";
} private void button15_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + " " + button15.Text + " ";
} private void button16_Click(object sender, EventArgs e)
{
textBox1.Text = "";
} private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
DialogResult dr=MessageBox.Show("确定退出吗","退出",MessageBoxButtons.OKCancel,MessageBoxIcon.Question);
if (dr==DialogResult.OK)
{
e.Cancel=false;
}
else
{
e.Cancel=true;
}
}
}
}

C#Windows Forms 计算器--xdd的更多相关文章

  1. C#Windows Forms窗体、按钮-xdd

    1.更换窗体图标 方法:单击窗体,更改icon属性. 2.调整窗体打开时默认位置 方法:单击窗体,更改StartPotion属性. 3.修改窗体大小 方法:单击窗体,更改Size属性. 4.设置窗体的 ...

  2. 开源自己用python封装的一个Windows GUI(UI Automation)自动化工具,支持MFC,Windows Forms,WPF,Metro,Qt

    首先,大家可以看下这个链接 Windows GUI自动化测试技术的比较和展望 . 这篇文章介绍了Windows中GUI自动化的三种技术:Windows API, MSAA - Microsoft Ac ...

  3. Wizard Framework:一个自己开发的基于Windows Forms的向导开发框架

    最近因项目需要,我自己设计开发了一个基于Windows Forms的向导开发框架,目前我已经将其开源,并发布了一个NuGet安装包.比较囧的一件事是,当我发布了NuGet安装包以后,发现原来已经有一个 ...

  4. windows forms 上一个类似于wpf snoop 的工具: Hawkeye

    windows forms 上一个类似于wpf snoop 的工具: Hawkeye 周银辉 WPF上有snoop这样的run time object editor让人用着很爽, 今天搜到了一个for ...

  5. WPF中实例化Com组件,调用组件的方法时报System.Windows.Forms.AxHost+InvalidActiveXStateException的异常

    WPF中实例化Com组件,调用组件的方法时报System.Windows.Forms.AxHost+InvalidActiveXStateException的异常 在wpf中封装Com组件时,调用组件 ...

  6. DotNetBar for Windows Forms 12.9.0.0_冰河之刃重打包版及制作Visual Studio C#项目模板文件详解

    关于 DotNetBar for Windows Forms 12.9.0.0_冰河之刃重打包版 --------------------11.8.0.8_冰河之刃重打包版-------------- ...

  7. DotNetBar for Windows Forms 12.7.0.10_冰河之刃重打包版原创发布-带官方示例程序版

    关于 DotNetBar for Windows Forms 12.7.0.10_冰河之刃重打包版 --------------------11.8.0.8_冰河之刃重打包版------------- ...

  8. DotNetBar for Windows Forms 12.5.0.2_冰河之刃重打包版原创发布-带官方示例程序版

    关于 DotNetBar for Windows Forms 12.5.0.2_冰河之刃重打包版 --------------------11.8.0.8_冰河之刃重打包版-------------- ...

  9. DotNetBar for Windows Forms 12.2.0.7_冰河之刃重打包版原创发布-带官方示例程序版

    关于 DotNetBar for Windows Forms 12.2.0.7_冰河之刃重打包版 --------------------11.8.0.8_冰河之刃重打包版-------------- ...

随机推荐

  1. C++两个队列实现一个栈

    C++两个队列实现一个栈 /* * source.cpp * * Created on: 2015年6月21日 * Author: codekiller */ #include "iostr ...

  2. SpringCloud之链路追踪整合Sleuth(十三)

    前言 SpringCloud 是微服务中的翘楚,最佳的落地方案. 在一个完整的微服务架构项目中,服务之间的调用是很复杂的,当其中某一个服务出现了问题或者访问超时,很 难直接确定是由哪个服务引起的,所以 ...

  3. ArangoDB图数据库--总参

    参考文章: ArangoDB原生多模型数据库(百科) ArangoDB官网 ArangoDB数据库入门 arangodb-vs-cassandra arangodb-vs-mongodb2 Arang ...

  4. js 的隐式转换与显式转换

    隐式转换   1.undefined与null相等,但不恒等(===) 2.一个是number一个是string时,会尝试将string转换为number 3.隐式转换将boolean转换为numbe ...

  5. redis is configured to save RDB snapshots

    Redis被配置为保存数据库快照,但它目前不能持久化到硬盘.用来修改集合数据的命令不能用 原因: 强制关闭Redis 快照导致不能持久化. 解决方法: 运行 config set stop-write ...

  6. 用node实现发送邮箱验证码

    首先,你需要注册一个支持发送的邮箱,我注册是网易邮箱,然后配置smtp. 然后,创建一个node项目,输入npm install nodemailer --save安装邮件依赖. 接着创建一个文件(s ...

  7. C++学习笔记8_零碎的知识

    1. int main(void) { int arr[] = {1,2,3,4}; //数组的长度 int len = sizeof(arr)/sizeof(int); //由此可以看出,sizeo ...

  8. 学习笔记59_python字符串处理

    python中,字符串可以使用 '或"括起来 1. 要想写成  "hellow "aaaa"  ",在python中,可以"hellow ' ...

  9. 「2019.7.22 考试」AC和WA0一步之遥

    这卷子还是答的挺惨的. 第一题5min写完了,自认为AC(其实WA了80),第二题推了半天CRT的公式老出错结果发现是程序打错了.第三题打模拟150行结果数组没开够,开大就是0->60的转变.状 ...

  10. 转:java 看好的一些书

    地址 :  http://www.cnblogs.com/xrq730/p/4994545.html