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 calculator
{
public partial class Form1 : Form
{
SpeechSynthesizer sp = new SpeechSynthesizer(); public Form1()
{
InitializeComponent();
} private void Add_Click(object sender, EventArgs e)
{
Compute compute = new Compute();
compute.set(number1, number2);
answer.Text = string.Format("{0}",compute.add());
sp.SpeakAsync(answer.Text);
} private void Subtract_Click(object sender, EventArgs e)
{
Compute compute = new Compute();
compute.set(number1, number2);
answer.Text = string.Format("{0}",compute.subtract());
sp.SpeakAsync(answer.Text);
} private void Multiply_Click(object sender, EventArgs e)
{
Compute compute = new Compute();
compute.set(number1, number2);
answer.Text = string.Format("{0}", compute.multiply());
sp.SpeakAsync(answer.Text);
} private void Divide_Click(object sender, EventArgs e)
{
Compute compute = new Compute();
compute.set(number1, number2);
answer.Text = string.Format("{0}", compute.divide());
sp.SpeakAsync(answer.Text);
} private void Power_Click(object sender, EventArgs e)
{
Compute compute = new Compute();
compute.set(number1, number2);
answer.Text = string.Format("{0}", compute.power());
sp.SpeakAsync(answer.Text);
} private void number1_TextChanged(object sender, EventArgs e)
{
string str = number1.Text.Trim(); for (int i = ; i < str.Length; i++)
{
if (!Char.IsNumber(str[i]))
{
number1.Text = string.Empty;
number1.BackColor = Color.Red;
}
else
{
number1.BackColor = Color.Empty;
}
}
} private void number2_TextChanged(object sender, EventArgs e)
{
string str = number2.Text.Trim();
for (int i = ; i < str.Length; i++)
{
if (!Char.IsNumber(str[i]))
{
number2.Text = string.Empty;
number2.BackColor = Color.Red;
}
else
{
number2.BackColor = Color.Empty;
}
}
} } class Compute {
private double a;
private double b;
private double x; public void set(object a, object b)
{
TextBox tempa = (TextBox)a;
TextBox tempb = (TextBox)b;
this.a = double.Parse(tempa.Text);
this.b = double.Parse(tempb.Text);
} public double add()
{
this.x = this.a + this.b;
return this.x;
} public double subtract()
{
this.x = this.a - this.b;
return this.x;
} public double multiply()
{
this.x = this.a * this.b;
return this.x;
} public double divide()
{
this.x = this.a / this.b;
return this.x;
} public double power()
{
this.x = Math.Pow(this.a, this.b);
return this.x;
}
}
}

看到这里您辛苦了,谢谢 : )

—————————————————————————————————————————————————————————————————————————————

声明:

  本文为 大Yi巴狼 对自己所学的知识整理和实现。

  本文档欢迎自由转载,但请务必保持本文档完整或注明来之本文档。本文档未经 大Yi巴狼 同意,不得用于商业用途。最后,如果您能从这个简单文档里获得些许帮助,大Yi巴狼 将对自己的一点努力感到非常高兴;由于作者本人水平有限,如果本文档中包含的错误给您造成了不便,在此提前说声抱歉。

  祝身体健康,工作顺利。

C# 学习之旅(3) --- 会说话的简易计算器的更多相关文章

  1. WCF学习之旅—第三个示例之四(三十)

           上接WCF学习之旅—第三个示例之一(二十七)               WCF学习之旅—第三个示例之二(二十八)              WCF学习之旅—第三个示例之三(二十九)   ...

  2. Hadoop学习之旅二:HDFS

    本文基于Hadoop1.X 概述 分布式文件系统主要用来解决如下几个问题: 读写大文件 加速运算 对于某些体积巨大的文件,比如其大小超过了计算机文件系统所能存放的最大限制或者是其大小甚至超过了计算机整 ...

  3. WCF学习之旅—第三个示例之二(二十八)

    上接WCF学习之旅—第三个示例之一(二十七) 五.在项目BookMgr.Model创建实体类数据 第一步,安装Entity Framework 1)  使用NuGet下载最新版的Entity Fram ...

  4. WCF学习之旅—第三个示例之三(二十九)

    上接WCF学习之旅—第三个示例之一(二十七) WCF学习之旅—第三个示例之二(二十八) 在上一篇文章中我们创建了实体对象与接口协定,在这一篇文章中我们来学习如何创建WCF的服务端代码.具体步骤见下面. ...

  5. WCF学习之旅—WCF服务部署到IIS7.5(九)

    上接   WCF学习之旅—WCF寄宿前的准备(八) 四.WCF服务部署到IIS7.5 我们把WCF寄宿在IIS之上,在IIS中宿主一个服务的主要优点是在发生客户端请求时宿主进程会被自动启动,并且你可以 ...

  6. WCF学习之旅—WCF服务部署到应用程序(十)

    上接  WCF学习之旅—WCF寄宿前的准备(八) WCF学习之旅—WCF服务部署到IIS7.5(九) 五.控制台应用程序宿主 (1) 在解决方案下新建控制台输出项目 ConsoleHosting.如下 ...

  7. WCF学习之旅—WCF服务的Windows 服务程序寄宿(十一)

    上接    WCF学习之旅—WCF服务部署到IIS7.5(九) WCF学习之旅—WCF服务部署到应用程序(十) 七 WCF服务的Windows 服务程序寄宿 这种方式的服务寄宿,和IIS一样有一个一样 ...

  8. WCF学习之旅—WCF服务的WAS寄宿(十二)

    上接    WCF学习之旅—WCF服务部署到IIS7.5(九) WCF学习之旅—WCF服务部署到应用程序(十) WCF学习之旅—WCF服务的Windows 服务程序寄宿(十一) 八.WAS宿主 IIS ...

  9. WCF学习之旅—WCF服务的批量寄宿(十三)

    上接    WCF学习之旅—WCF服务部署到IIS7.5(九) WCF学习之旅—WCF服务部署到应用程序(十) WCF学习之旅—WCF服务的Windows 服务程序寄宿(十一) WCF学习之旅—WCF ...

随机推荐

  1. 详解ARM的AMBA设备中的 DMA设备PL08X的Linux驱动

    1. 此文目的记录笔者对ARM的PL08x的DMA驱动PL08x.c理解.给其他不熟悉此DMA驱动的读者一点借鉴和参考.2. 适合读者你已经具备一定驱动编程能力,知道一些最基本的概念,比如用于输出输出 ...

  2. eclipse 的小技巧

    1. ctrl+o:快速outline 如果想要查看当前类的方法或某个特定方法,但又不想把代码拉上拉下,也不想使用查找功能的话,就用ctrl+o吧.它可以列出当前类中的所有方法及属性,你只需输入你想要 ...

  3. ASP.NET 之 检测到在集成的托管管道模式下不适用的ASP.NET设置

    将ASP.NET程序从IIS6移植到IIS7后,调试运行可能提示以下错误: HTTP 错误 500.23 - Internal Server Error 检测到在集成的托管管道模式下不适用的 ASP. ...

  4. Algernon's Noxious Emissions POJ1121 zoj1052

    One of the greatest alchemists of the lower Middle Renaissance, Algernon da Vinci (one of Leonardo's ...

  5. Android SQLite 数据库详细介绍

    Android SQLite 数据库详细介绍 我们在编写数据库应用软件时,需要考虑这样的问题:因为我们开发的软件可能会安装在很多用户的手机上,如果应用使用到了SQLite数据库,我们必须在用户初次使用 ...

  6. 如何用C表示排列组合?

    问题来自<Linux C一站式编程>,是个挺有意思的题目. 2.定义一个数组,编程打印它的全排列.比如定义: #define N 3 int a[N] = { 1, 2, 3 }; 则运行 ...

  7. coherence配置说明

    经过上篇 coherence初识 ,最近算是和coherence杠上了,针对coherence3.5.3这个版本,把学到的东西整理下 1. 这个jar包有点大,4M多,首先打开coherence.ja ...

  8. [改善Java代码]不要覆写静态方法

    建议33: 不要覆写静态方法 我们知道在Java中可以通过覆写(Override)来增强或减弱父类的方法和行为,但覆写是针对非静态方法(也叫做实例方法,只有生成实例才能调用的方法)的,不能针对静态方法 ...

  9. poj 2057 树形dp 贪心

    思路:设sum[i],le[i],back[i],worm[i]分别表示以i为根节点需要的完成步数,叶子节点数,失败回退步数,以及i是否有虫. #include<iostream> #in ...

  10. 转: android studio 消除SDK更新时的“https://dl-ssl.google.com refused”错误

    消除了: hostname in certificate didn't match: 转: http://blog.csdn.net/gaojinshan/article/details/987160 ...