一、计算器

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. LoadRunner脚本优化—迭代的组合用法

    Elect next row——选择下一行 Sequential:顺序取行 Random:随机取行 Unique:每一个值只能使用一次 中止:abort Vuser 循环Vuser分配到的列表 只循环 ...

  2. 基于redis解决session分布式一致性问题

    1.session是什么 当用户在前端发起请求时,服务器会为当前用户建立一个session,服务器将sessionId回写给客户端,只要用户浏览器不关闭,再次请求服务器时,将sessionId传给服务 ...

  3. Redis(十二)flush误操作、Redis安全、处理bigkey和寻找热点key

    一.flushall/flushdb误操作的处理 假设进行flush操作的Redis是一对主从结构的主节点,其中键值对的个数是100万,每秒写入量是1000. 1.缓存与存储 被误操作flush后,根 ...

  4. Linux 操作点滴

    1. 查找文件内容 find -type f -name '*' | xargs grep '' 2. 查看所有环境变量 env 3. so动态库文件查找路径:/lib    /usr/lib   / ...

  5. Flask:第一个Flask项目

    在上一篇文章:Flask:项目的准备工作中,我写了flask项目的准备工作,不清楚创建flask项目需要做哪些准备的朋友可以点击链接看看 1.最简单的Flask项目 代码: from flask im ...

  6. MSF系列--MS17_010利用模块笔记

    1.   auxiliary/scanner/smb/smb_ms17_010      //扫描检测漏洞辅助模块 扫描结果这里可以看到 2,3,4这几台主机存在此漏洞! 2.     auxilia ...

  7. Vs使用EF来操作MySql(经验 )

    1.安装Vs2015,至少是2012以上版本才行 2. 安装 这个是用于连接Mysql数据库的Vs插件 2.1通过这种方式添加引用 3.配置数据库 // // // 4.添加实体 注:这里最好从数据库 ...

  8. NOIP模拟测试8反思

    被动态逆序对戏耍,来写博客这次考试油炸了 模板爆零,哈希调半天导致T3没时间,我都干了些什么&_& T3思路: 利用环的性质先拼成一条链,然后二分边界. 证明就不说啦(其实是我不会) ...

  9. sshd服务及基于密钥远程登陆(无需密码)

    上一条博客说明了用sshd服务远程登陆另一个系统,但是需要密码,如果不用密码呢?有没有简便的方法呢?下面为大家介绍一下,也就是基于密钥的安全验证:需要在本地生成”密钥对“后将公钥传送至服务端,进行公共 ...

  10. curl太复杂难用记不住?来试试Httpie一个简单的现代化命令行Http客户端

    HTTPie 是一个简单的现代化命令行 HTTP 客户端. 交互友好,JSON支持,语法高亮,类wget下载,支持拓展等 功能特性 自然而且简单的命令语句 格式化且高亮显示输出内容 内置 JSON 支 ...