| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 530 人关注过本帖
标题:制作的计算器
只看楼主 加入收藏
Snow_Pu
Rank: 2
等 级:论坛游民
帖 子:27
专家分:45
注 册:2011-5-11
结帖率:100%
收藏
 问题点数:0 回复次数:3 
制作的计算器
Calculator.rar (40.48 KB)
搜索更多相关主题的帖子: 计算器 
2011-05-13 13:11
xp白马飞马
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2011-8-7
收藏
得分:0 
[local]1[/local]
2011-08-08 11:24
xp白马飞马
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2011-8-7
收藏
得分:0 
[local]1[/local]发不上去????????
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void kong()
        {
            if (t.Text == "0" || shu == "+" || shu == "-" || shu == "*" || shu == "/" || shu == "=" || shu == "NO")
            {
                t.Text = "";
            }
        }

        //1
        private void b1_Click(object sender, EventArgs e)
        {
            dian = "NO";
            if (myhuhao == "=")
            {
                MessageBox.Show("请选 + - * / 在按数字");
            }
            else
            {
                kong();
                shu = "1";
                if (shu == "1")
                {
                    t.Text = t.Text + 1;
                }
            }
        }
        //3
        private void b3_Click(object sender, EventArgs e)
        {
            dian = "NO";
            if (myhuhao == "=")
            {
                MessageBox.Show("请选 + - * / 在按数字");
            }
            else
            {
                kong();
                shu = "3";
                if (shu == "3")
                {
                    t.Text = t.Text + 3;
                }
            }
        }
        //6
        private void b6_Click(object sender, EventArgs e)
        {
            dian = "NO";
            if (myhuhao == "=")
            {
                MessageBox.Show("请选 + - * / 在按数字");
            }
            else
            {
                kong();
                shu = "6";
                if (shu == "6")
                {
                    t.Text = t.Text + 6;
                }
            }
        }
        //5
        private void b5_Click(object sender, EventArgs e)
        {
            dian = "NO";
            if (myhuhao == "=")
            {
                MessageBox.Show("请选 + - * / 在按数字");
            }
            else
            {
                kong();
                shu = "5";
                if (shu == "5")
                {
                    t.Text = t.Text + 5;
                }
            }
        }
        //4
        private void b4_Click(object sender, EventArgs e)
        {
            dian = "NO";
            if (myhuhao == "=")
            {
                MessageBox.Show("请选 + - * / 在按数字");
            }
            else
            {
                kong();
                shu = "4";
                if (shu == "4")
                {
                    t.Text = t.Text + 4;
                }
            }
        }
        //7
        private void b7_Click(object sender, EventArgs e)
        {
            dian = "NO";
            if (myhuhao == "=")
            {
                MessageBox.Show("请选 + - * / 在按数字");
            }
            else
            {
                kong();
                shu = "7";
                if (shu == "7")
                {
                    t.Text = t.Text + 7;
                }
            }
        }
        //8
        private void b8_Click(object sender, EventArgs e)
        {
            dian = "NO";
            if (myhuhao == "=")
            {
                MessageBox.Show("请选 + - * / 在按数字");
            }
            else
            {
                kong();
                shu = "8";
                if (shu == "8")
                {
                    t.Text = t.Text + 8;
                }
            }
        }
        //9
        private void b9_Click(object sender, EventArgs e)
        {
            dian = "NO";
            if (myhuhao == "=")
            {
                MessageBox.Show("请选 + - * / 在按数字");
            }
            else
            {
                kong();
                shu = "9";
                if (shu == "9")
                {
                    t.Text = t.Text + 9;
                }
            }
        }
        //0
        private void b0_Click(object sender, EventArgs e)
        {
            dian = "NO";
            if (myhuhao == "=")
            {
                MessageBox.Show("请选 + - * / 在按数字");
            }
            else
            {
                kong();
                shu = "0";
                if (shu == "0")
                {
                    t.Text = t.Text + 0;
                }
            }
        }

        decimal i = 0;
        string shu = "";
        string huhao = "";
        string myhuhao = "";
        //jia 加
         private void jia_Click(object sender, EventArgs e)
        {
            decimal a = 0;
            a = a + i;
            if (myhuhao == "+")
             {
                 if (shu == "1" || shu == "2" || shu == "3" || shu == "4" || shu == "5" || shu == "6" || shu == "7" || shu == "8" || shu == "9" || shu == "0")
                 {
                     myhuhao = "+";
                 }
                 else
                 {
                     return;
                 }
             }
            bool aa = decimal.TryParse(t.Text, out i);
            if (aa == true)
            {
                if (a == 0)
                {
                    t.Text = t.Text;
                    if (myhuhao == "*")
                    {
                        t.Text = (a * Convert.ToDecimal(t.Text)).ToString();
                    }
                }
                else
                {
                    if (shu == "1" || shu == "2" || shu == "3" || shu == "4" || shu == "5" || shu == "6" || shu == "7" || shu == "8" || shu == "9" || shu == "0")
                    {
                        if (myhuhao == "+")
                        {
                            t.Text = (a + Convert.ToDecimal(t.Text)).ToString();
                        }
                        else if (myhuhao == "-")
                        {
                            t.Text = (a - Convert.ToDecimal(t.Text)).ToString();
                        }
                        else if (myhuhao == "*")
                        {
                            t.Text = (a * Convert.ToDecimal(t.Text)).ToString();
                        }
                        else if (myhuhao == "/")
                        {
                            if (t.Text == "0")
                            {
                                MessageBox.Show("除数不为0");
                            }
                            else
                            {
                                t.Text = (a / Convert.ToDecimal(t.Text)).ToString();
                            }
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("只可以输入数字");
            }
            decimal.TryParse(t.Text, out i);
            if (aa == true)
            {
                shu = "+";
                huhao = "+";
                myhuhao = "+";
                dian = "off";
            }                                                                           
        }

        //jian 减
        private void jian_Click(object sender, EventArgs e)
          {
            decimal a = 0;
            a = a + i;
            if (myhuhao == "-")
            {
                if (shu == "1" || shu == "2" || shu == "3" || shu == "4" || shu == "5" || shu == "6" || shu == "7" || shu == "8" || shu == "9" || shu == "0")
                {
                    myhuhao = "-";
                }
                else
                {
                    return;
                }
            }
            bool aa = decimal.TryParse(t.Text, out i);
            if (aa == true)
            {
                if (a == 0)
                {
                    t.Text = t.Text;
                    if (myhuhao == "*")
                    {
                        t.Text = (a * Convert.ToDecimal(t.Text)).ToString();
                    }
                }
                else
                {
                    if (shu == "1" || shu == "2" || shu == "3" || shu == "4" || shu == "5" || shu == "6" || shu == "7" || shu == "8" || shu == "9" || shu == "0")
                    {
                        if (myhuhao == "+")
                        {
                            t.Text = (a + Convert.ToDecimal(t.Text)).ToString();
                        }
                        else if (myhuhao == "-")
                        {
                            t.Text = (a - Convert.ToDecimal(t.Text)).ToString();
                        }
                        else if (myhuhao == "*")
                        {
                            t.Text = (a * Convert.ToDecimal(t.Text)).ToString();
                        }
                        else if (myhuhao == "/")
                        {
                            if (t.Text == "0")
                            {
                                MessageBox.Show("除数不为0");
                            }
                            else
                            {
                                t.Text = (a / Convert.ToDecimal(t.Text)).ToString();
                            }
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("只可以输入数字");
            }
            decimal.TryParse(t.Text, out i);
            if (aa == true)
            {
                shu = "-";
                huhao = "-";
                myhuhao = "-";
                dian = "off";
            }
        }
        //cheng 乘
        private void cheng_Click(object sender, EventArgs e)
        {
            decimal a = 0;
            a = a + i;
            if (myhuhao == "*")
            {
                if (shu == "1" || shu == "2" || shu == "3" || shu == "4" || shu == "5" || shu == "6" || shu == "7" || shu == "8" || shu == "9" || shu == "0")
                {
                    myhuhao = "*";
                }
                else
                {
                    return;
                }
            }
            bool aa = decimal.TryParse(t.Text, out i);
            if (aa == true)
            {
                if (a == 0)
                {
                    t.Text = t.Text;
                    if (myhuhao == "*")
                    {
                        t.Text = (a * Convert.ToDecimal(t.Text)).ToString();
                    }
                }
                else
                {
                    if (shu == "1" || shu == "2" || shu == "3" || shu == "4" || shu == "5" || shu == "6" || shu == "7" || shu == "8" || shu == "9" || shu == "0")
                    {
                        if (myhuhao == "+")
                        {
                            t.Text = (a + Convert.ToDecimal(t.Text)).ToString();
                        }
                        else if (myhuhao == "-")
                        {
                            t.Text = (a - Convert.ToDecimal(t.Text)).ToString();
                        }
                        else if (myhuhao == "*")
                        {
                            t.Text = (a * Convert.ToDecimal(t.Text)).ToString();
                        }
                        else if (myhuhao == "/")
                        {
                            if (t.Text == "0")
                            {
                                MessageBox.Show("除数不为0");
                            }
                            else
                            {
                                t.Text = (a / Convert.ToDecimal(t.Text)).ToString();
                            }
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("只可以输入数字");
            }
            decimal.TryParse(t.Text, out i);
            if (aa == true)
            {
                shu = "*";
                huhao = "*";
                myhuhao = "*";
                dian = "off";
            }
        }
        //chu 除
        private void chu_Click(object sender, EventArgs e)
        {
            decimal a = 0;
            a = a + i;
            if (myhuhao == "/")
            {
                if (shu == "1" || shu == "2" || shu == "3" || shu == "4" || shu == "5" || shu == "6" || shu == "7" || shu == "8" || shu == "9" || shu == "0")
                {
                    myhuhao = "/";
                }
                else
                {
                    return;
                }
            }
            bool aa = decimal.TryParse(t.Text, out i);
            if (aa == true)
            {
                if (a == 0)
                {
                    t.Text = t.Text;
                    if (myhuhao == "*")
                    {
                        t.Text = (a * Convert.ToDecimal(t.Text)).ToString();
                    }
                }
                else
                {
                    if (shu == "1" || shu == "2" || shu == "3" || shu == "4" || shu == "5" || shu == "6" || shu == "7" || shu == "8" || shu == "9" || shu == "0")
                    {
                        if (myhuhao == "+")
                        {
                            t.Text = (a + Convert.ToDecimal(t.Text)).ToString();
                        }
                        else if (myhuhao == "-")
                        {
                            t.Text = (a - Convert.ToDecimal(t.Text)).ToString();
                        }
                        else if (myhuhao == "*")
                        {
                            t.Text = (a * Convert.ToDecimal(t.Text)).ToString();
                        }
                        else if (myhuhao == "/")
                        {
                            if (t.Text == "0")
                            {
                                MessageBox.Show("除数不为0");
                            }
                            else
                            {
                                t.Text = (a / Convert.ToDecimal(t.Text)).ToString();
                            }
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("只可以输入数字");
            }
            decimal.TryParse(t.Text, out i);
            if (aa == true)
            {
                shu = "/";
                huhao = "/";
                myhuhao = "/";
                dian = "off";
            }
        }
        //deng 等
        private void deng_Click(object sender, EventArgs e)
        {
            if (shu == "1" || shu == "2" || shu == "3" || shu == "4" || shu == "5" || shu == "6" || shu == "7" || shu == "8" || shu == "9" || shu == "0")
            {
                myhuhao = "=";
            }
            else
            {
                return;
            }
            if (huhao == "+")
            {
                t.Text = (i + Convert.ToDecimal(t.Text)).ToString();
            }
            else if (huhao == "-")
            {
                t.Text = (i - Convert.ToDecimal(t.Text)).ToString();
            }
            else if (huhao == "*")
            {
                t.Text = (i * Convert.ToDecimal(t.Text)).ToString();
            }
            else if (huhao == "/")
            {
                if (t.Text == "0")
                {
                    MessageBox.Show("除数不为0");
                    dian = "NO";
                    myhuhao = "NO";
                    t.Text = "0";
                    i = 0;
                    huhao = "off";
                    return;
                }
                else
                {
                    t.Text = (i / Convert.ToDecimal(t.Text)).ToString();
                }
            }
            myhuhao = "=";
            shu = "NO";
            dian = "off";
        }

        //2
        private void b2_Click(object sender, EventArgs e)
        {
            dian = "NO";
            if (myhuhao == "=")
            {
                MessageBox.Show("请选 + - * / 在按数字");
            }
            else
            {
                kong();
                shu = "2";

                if (shu == "2")
                {
                    t.Text = t.Text + 2;
                }
            }
        }

        //C
        private void C_Click(object sender, EventArgs e)
        {
            dian = "NO";
            myhuhao = "NO";
            t.Text = "0";
            i = 0;
            huhao = "off";
        }

        //点

        string dian = "";

        private void bu1_Click(object sender, EventArgs e)
        {
            if (dian == "off")
            {
                MessageBox.Show("按了 + - * / 不可以按<点>请选按数字,再按点.如:0.1等...");
            }
            else
            {
                //t.Text = ".";
                if (t.Text == "")
                {
                    //t.Text = "请输入数字";
                    return;
                }
                if (t.Text.IndexOf('.') == -1)
                {
                    //t.text.indexof('.') 是查找字符串t中,字符"." 的位置  
                    // 如果t中没有包含 .那么会返回 -1

                    //找不到
                    t.Text = t.Text + ".";
                }
                else
                {
                    //找到. 已存在一个.
                    return;
                }
            }
        }
    }
}
希望可以帮到你
2011-08-08 11:28
缘似梦
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-12-12
收藏
得分:0 
很有用
2011-12-12 19:39
快速回复:制作的计算器
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.129863 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved