这是一个课堂作业,我觉得作为一个简易的计算器不需要态度复杂的东西,可能还有一些bug,有空再慢慢加强。

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;
using System.Speech;
using System.Speech.Synthesis;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
SpeechSynthesizer sp = new SpeechSynthesizer();
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
this.Text = "简易计算器";
}

private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text != string.Empty && textBox2.Text != string.Empty)
{
double a = double.Parse(textBox1.Text);
double b = double.Parse(textBox2.Text);
textBox3.Text = String.Format("结果是{0}", (a + b));
sp.SpeakAsync(textBox3.Text);
}
else
{
textBox3.Text = "输入条件不足";
}
}

private void button2_Click(object sender, EventArgs e)
{
if (textBox1.Text != string.Empty && textBox2.Text != string.Empty)
{
double a = double.Parse(textBox1.Text);
double b = double.Parse(textBox2.Text);
textBox3.Text = String.Format("结果是{0}", (a - b));
sp.SpeakAsync(textBox3.Text);
}
else
{
textBox3.Text = "输入条件不足";
}
}

private void button3_Click(object sender, EventArgs e)
{
if (textBox1.Text != string.Empty && textBox2.Text != string.Empty)
{
double a = double.Parse(textBox1.Text);
double b = double.Parse(textBox2.Text);
textBox3.Text = String.Format("结果是{0}", (a*b));
sp.SpeakAsync(textBox3.Text);
}
else
{
textBox3.Text = "输入条件不足";
}
}

private void button4_Click(object sender, EventArgs e)
{
if (textBox1.Text != string.Empty && textBox2.Text != string.Empty)
{
double a = double.Parse(textBox1.Text);
double b = double.Parse(textBox2.Text);
textBox3.Text = String.Format("结果是{0}", (a / b));
sp.SpeakAsync(textBox3.Text);
}
else
{
textBox3.Text = "输入条件不足";
}
}

private void button5_Click(object sender, EventArgs e)
{
if (textBox1.Text != string.Empty && textBox2.Text != string.Empty)
{
double a = double.Parse(textBox1.Text);
textBox3.Text = String.Format("结果是{0}", (Math.Sqrt(a)));
sp.SpeakAsync(textBox3.Text);}
else
{
textBox3.Text = "输入条件不足";
}

}
}
}

自制c#简易计算器的更多相关文章

  1. 大一C语言学习笔记(10)---编程篇--制作简易计算器,支持加,减,乘,除,取余运算,要求 0 bug

    博主自开学初就一直在努力为自己的未来寻找学习方向,学习编程嘛,尽量还是要抱大腿的,所以我就加入了我们学校的智能设备研究所,别的不说,那的学长们看起来是真的很靠谱,学长们的学习氛围也超级浓厚,所以我就打 ...

  2. 剖析简易计算器带你入门微信小程序开发

    写在前面,但是重点在后面 这是教程,也不是教程. 可以先看Demo的操作动图,看看是个什么玩意儿,GitHub地址(https://github.com/dunizb/wxapp-sCalc) 自从微 ...

  3. PHP学习笔记02——简易计算器

    <!DOCTYPE html> <html> <head> <title>PHP简易计算器</title> </head> &l ...

  4. JavaScript之简易计算器

    <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8&quo ...

  5. 菜鸟学习Struts——简易计算器

    这是学习Struts的一个简单的例子文件结构如下: 1.配置Struts环境 2.新建input.jsp,success.jsp,error.jsp input.jsp代码如下: <%@ pag ...

  6. Python之实现一个简易计算器

    自己动手写计算器 一.功能分析 用户输入一个类似这样 3*( 4+ 50 )-(( 100 + 40 )*5/2- 3*2* 2/4+9)*((( 3 + 4)-4)-4) 这样的表达式,假设表达式里 ...

  7. 使用HTML+CSS,jQuery编写的简易计算器

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...

  8. 使用HTML+CSS,jQuery编写的简易计算器后续(添加了键盘监听)

    之前发布了一款简易的计算器,今天做了一下修改,添加了键盘监听事件,不用再用鼠标点点点啦 JS代码: var yunSuan = 0;// 运算符号,0-无运算;1-加法;2-减法;3-乘法;4-除法 ...

  9. C#Windows Form简易计算器实现(中)

    昨天花了一天的时间弄计算器.也算是做出来了,还是简易的(怀疑猿生!!).在此先感谢昨天被我骚扰的朋友. 先贴一张界面看看 其实健壮性还是挺差的,用户体验也是极差的.比如说用户输入了不合理运算式子,我就 ...

随机推荐

  1. Json解析实例

    using System; using System.Collections.Generic; using System.Runtime.Serialization; using System.Win ...

  2. 关于node.js杂记

    https://gitlore.com/page/gitlore-git/nodejs/index.html[node.js中文文档] //////    https://gitlore.com/in ...

  3. Ubuntu下的Notepad++:Notepadqq

    http://www.linuxidc.com/Linux/2015-07/120678.htm 适合从Win平台转移到Linux平台的用户,如果你之前一直再Win下使用nodepad++, 推荐你再 ...

  4. (转载)MongoDB C#驱动中Query几个方法

    MongoDB C#驱动中Query几个方法 Query.All("name", "a", "b");//通过多个元素来匹配数组 Query ...

  5. SpringMVC生成任意文件,访问链接即下载

    原理上讲就是返回的 ResponseEntity<byte[]> 形式的值就可以了 @RequestMapping("/api/watermark_download") ...

  6. JDBC + MySQL 示例

    jdbc mysql connection 教程 翻译自:JDBC MySQL Connection Tutorial Java Database Connectivity (JDBC) 是一个基于J ...

  7. Git_1基础操作,从安装到提交完成(windows)

    github地址:https://github.com/zhangsai521314/Git 1:安装Git Bash(https://git-scm.com/),安装一路NEXT. 2:目录架构: ...

  8. 【IOS 开发】Object - C 入门 之 数据类型详解

    1. 数据类型简介及输出() http://www.把下面的替换我.com/html/topnews201408/79/1279.htm csdn123

  9. struct结构体(剽窃别人的)

    结构是使用 struct 关键字定义的,与类相似,都表示可以包含数据成员和函数成员的数据结构. 一般情况下,我们很少使用结构,而且很多人也并不建议使用结构,但作为.NET Framework 一般型別 ...

  10. RANSAC 剔除错误匹配 估计模型

    随机抽样一致,这个算法,我以前一直都没有理解透彻.只知道可以用来直线拟合,网上大多数中文博客也都是写直线拟合的,但是用来匹配二维特征的时候,总还是没弄明白. 基本概念参考 http://www.cnb ...