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. 解决位图失真-SetStretchBltMode()

    当用以下函数加载一张位图时,当窗口发生重绘更改大小时,位图将失真: CBitmap bitmap;  bitmap.LoadBitmap(IDB_BITMAP2); BITMAP bmp;  bitm ...

  2. 渐进式jpeg(progressive jpeg)图片及其相关 --图片的两种加载方式

    渐进式jpeg(progressive jpeg)图片及其相关   一.基本JPEG(baseline jpeg)和渐进JPEG 网络上那些色色的照片都是.jpg格式的("色色"指 ...

  3. Android 自学之画廊视图(Gallery)功能和用法

    Gallery与之前讲的Spinner有共同的父类:AbsSpinner,表明Gallery和Spinner都是一个列表框.他们之间的区别在于Spinner显示的是一个垂直的列表框,而Gallery显 ...

  4. JDBC的批量查询报告内存溢出解决方法

    由于表中的数据过多(我的超过了50W+),查询select * from table ....报告内存溢出 Exception in thread "main" java.lang ...

  5. 【二进制】FZU 2062 Suneast & Yayamao

    题意:给出n,问最少需要多少个数字,这些数字能组成1~n的所有数: 分析:n=1; 1; 1个 n=2; 1,1;  2个 1 = 1; 2 = 1+1;   n=3; 1,2; 2个 1 = 1; ...

  6. hdu 4607 树的直径

    思路:利用dfs遍历整棵树,找出最长子树与次长子树,两者的和最大就是直径. 若k值小于直径就输出k-1,否则输出(k-d-1)*2+d; #include<iostream> #inclu ...

  7. scikit-learn点滴

    scikit-learn点滴 scikit-learn是非常漂亮的一个机器学习库,在某些时候,使用这些库能够大量的节省你的时间,至少,我们用Python,应该是很难写出速度快如斯的代码的. sciki ...

  8. echars3.0 柱状图y轴字体斜放

    xAxis: [ { type: 'category', axisLabel: { interval: 0, rotate: 45,//倾斜角度设置,是什么时针未测 margin: 2 //距离上部的 ...

  9. Jersey(1.19.1) - Hello World, Get started with a Web application

    1. Maven Dependency <properties> <jersey.version>1.19.1</jersey.version> </prop ...

  10. HDOJ2029Palindromes _easy version

    Palindromes _easy version Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav ...