一、计算器

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. 【ASP.NET Core学习】Razor页面

    准备工作 初始化空的项目(终端输入:dotnet new web -n=Razor) Nuget添加Microsoft.EntityFrameworkCore.SqlServer 和 Microsof ...

  2. TCP连接的关闭

    原文地址:http://lib.csdn.net/article/computernetworks/17264   TCP连接的关闭有两个方法close和shutdown,这篇文章将尽量精简的说明它们 ...

  3. Python enumerate() 函数笔记

    enumerate函数说明: 函数原型:enumerate(sequence, [start=0])  #第二个参数为指定索引 功能:将可循环序列sequence以start开始分别列出序列数据和数据 ...

  4. 明解C语言 入门篇 第三章答案

    练习3-1 #include <stdio.h> int main() { int x; int y; puts("请输入两个整数."); printf("整 ...

  5. 学习笔记24_MVC前后台数据交互

    *最普通的交互方式,在Contoller中的Action方法内 public ActionResult Index() { ViewData["Key"] =Value; Retu ...

  6. shell 字符串比较与脚本 too many arguments 报错

    一.问题 最近在写 shell 脚本的时候,遇到了一些小问题,就是我在判断一个字符串是否为空的时候经常报下面的错,程序是正常执行了,但是有这个提示很蛋疼,下面就是看看是什么问题导致的? [: too ...

  7. NOIP模拟测试2-5

    该补一下以前挖的坑了 先总结一下 第二次 T1 搜索+剪枝 #include<cstdio> #include<iostream> #define ll long long u ...

  8. javascript 字符串转化成函数执行

    javascript 字符串转化成函数执行<pre>function func_abc(){ alert('a');}var str = "func_abc";eval ...

  9. egret Tiledmap编写障碍物的思路

    egret Tiledmap编写障碍物的思路 获取控制对象下一刻移动的坐标,将其转换成瓦片坐标,如果getTileGIDAt(根据瓦片坐标获取瓦片id)的值不为0,说明对象将要移动的位置有障碍物,不做 ...

  10. csp-s2019游记

    11.15D0: 复习 复习 机房里弥漫着颓废的气息,不过也是最后一个下午了 11.16D1: 五点钟爬起来,一边发抖一边去楼下买早饭 虽然平时基本不吃早饭,但考前不行 搭着同学的车去了考点,在车上重 ...