zoukankan      html  css  js  c++  java
  • 自制c#简易计算器

    这是一个课堂作业,我觉得作为一个简易的计算器不需要态度复杂的东西,可能还有一些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 = "输入条件不足";
    }

    }
    }
    }

  • 相关阅读:
    handler之责任链模式
    简单的PL/SQl链接远程ORACLE数据库方法
    An internal error occurred during: "Add Deployment". Container with path org.eclipse.jdt.launching.
    myeclipse非正常关闭处理办法
    jQuery Plugin Poshy Tip 使用 统一提示信息
    myeclipse部署maven时,src/main/resources里面配置文件加载不到webapp下classes路径下的问题
    CSS实现背景透明,文字不透明,兼容所有浏览器
    @SuppressWarnings注解
    @GeneratorValue与@GenericGenerator注解使用心得
    jap的教程
  • 原文地址:https://www.cnblogs.com/huailehang/p/3629673.html
Copyright © 2011-2022 走看看