欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C#实现Winform版计算器

程序员文章站 2022-06-05 14:15:19
本文实例为大家分享winform版计算器的具体实现方法,供大家参考,具体内容如下 前台页面设计 后台代码实现 using system; using...

本文实例为大家分享winform版计算器的具体实现方法,供大家参考,具体内容如下

前台页面设计

C#实现Winform版计算器

后台代码实现

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 计算器
{
  public partial class form1 : form
  {
    double c, d;
    string m;
    public form1()
    {
      initializecomponent();
    }




    private void button2_click(object sender, eventargs e)
    {


    }


    private void button8_click(object sender, eventargs e)
    {
      textbox1.text += button8.text;
    }


    private void button1_click(object sender, eventargs e)
    {
      textbox1.text += button1.text;
    }


    private void button2_click_1(object sender, eventargs e)
    {
      textbox1.text += button2.text;


    }


    private void button3_click(object sender, eventargs e)
    {
      textbox1.text += button3.text;
    }


    private void button4_click(object sender, eventargs e)
    {
      textbox1.text += button4.text;
    }


    private void button5_click(object sender, eventargs e)
    {
      textbox1.text += button5.text;
    }


    private void button6_click(object sender, eventargs e)
    {
      textbox1.text += button6.text;
    }


    private void button7_click(object sender, eventargs e)
    {
      textbox1.text += button7.text;


    }


    private void button9_click(object sender, eventargs e)
    {
      textbox1.text += button9.text;
    }


    private void button10_click(object sender, eventargs e)
    {
      textbox1.text += button10.text;
    }


    private void button15_click(object sender, eventargs e)
    {
      d= convert.todouble(textbox1.text);
      switch (m)
      { 
        case("+"):
          textbox1.text = convert.tostring(c+d);
          break;
        case ("-"):
          textbox1.text = convert.tostring(c-d);
          break;
        case ("*"):
          textbox1.text = convert.tostring(c * d);
          break;
        case ("/"):
          textbox1.text = convert.tostring(c/d);
          break;


      }
    }


    private void button11_click(object sender, eventargs e)
    {
      c = convert.todouble(textbox1.text);
      textbox1.text = "";
      m = button11.text;
    }


    private void button12_click(object sender, eventargs e)
    {
      c = convert.todouble(textbox1.text);
      textbox1.text = "";
      m = button12.text;
    }


    private void button13_click(object sender, eventargs e)
    {
      c= convert.todouble(textbox1.text);
      textbox1.text = "";
      m = button13.text;
    }


    private void button14_click(object sender, eventargs e)
    {
      c = convert.todouble(textbox1.text);
      textbox1.text = "";
      m = button14.text;
    }


    private void button16_click(object sender, eventargs e)
    {
      textbox1.text = "";
    }
  }
}

以上就是本文的全部内容,希望对大家学习c#程序设计有所帮助。