| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 409 人关注过本帖
标题:我用c#编辑的一个计算器,求大神指点
只看楼主 加入收藏
张力川
Rank: 1
等 级:新手上路
帖 子:2
专家分:2
注 册:2011-11-25
收藏
 问题点数:0 回复次数:0 
我用c#编辑的一个计算器,求大神指点
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        int flag;
        double num1;
        double result;

        public Form1()
        {
            InitializeComponent();
        }

        private void num_Click(object sender, EventArgs e)
        {
            Button a = (Button)sender;
            textBox1.Text = textBox1.Text + a.Text;
        }

        private void operator_Click(object sender, EventArgs e)
        {
            Button b = (Button)sender;
            if (b.Text == "+")
            {
                num1 = double.Parse(textBox1.Text);
                textBox1.Text = "";
                flag = 0;
            }
            if (b.Text == "-")
            {
                num1 = double.Parse(textBox1.Text);
                textBox1.Text = "";
                flag = 1;
            }
            if (b.Text == "*")
            {
                num1 = double.Parse(textBox1.Text);
                textBox1.Text = "";
                flag = 2;
            }
            if (b.Text == "/")
            {
                num1 = double.Parse(textBox1.Text);
                textBox1.Text = " ";
                flag = 3;
            }
            if (b.Text == "C")
            {
                textBox1.Text = "";
                num1 = 0;
                textBox1.Focus();
            }
            if(b.Text=="=")
            {
                switch(flag)
                {
                    case 0:
                        result=num1+double.Parse(textBox1.Text);
                        break;
                    case 1:
                        result=num1-double.Parse (textBox1.Text);
                        break;
                    case 2:
                        result=num1*double.Parse(textBox1.Text);
                        break;
                    case 3:
                        result=num1/double.Parse(textBox1.Text);
                        break;

                }
                textBox1.Text=result.ToString();
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void oo_Click(object sender, EventArgs e)
        {
            //int i = 0;
            Button c = (Button)sender;
            Button a = (Button)sender;
            if (c.Text == "0")
            {
                if (textBox1.Text == "")
                    textBox1.Text = "0.";
                else
                    textBox1.Text = textBox1.Text+a.Text;
            }
            if (c.Text == ".")
            {
                string str_msg = textBox1.Text;
                if (str_msg.IndexOf('.') == -1)
                    textBox1.Text = textBox1.Text + a.Text;
                else
                    textBox1.Text = textBox1.Text;
            }
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }
        double w;
        private void xx_Click(object sender, EventArgs e)
        {
            
            Button d= (Button)sender;
            if (d.Text == "MS")//MS是保存
            {
                textBox2.Text = textBox1.Text;
            }
            if (d.Text == "M+")//M+是叠加
            {
               
                double w = double.Parse(textBox1.Text)+double.Parse(textBox2.Text);
                textBox1.Text = w.ToString();
                //textBox1.Text = w.ToString();
            }
            if (d.Text == "MR")//MR是读取
            {
                textBox1.Text = textBox2.Text;
            }
            if (d.Text == "MC")//MC是清空
            {
                textBox2.Text = " ";
            }
        }

      
    }
}
搜索更多相关主题的帖子: double void private public result 
2012-11-07 12:40
快速回复:我用c#编辑的一个计算器,求大神指点
数据加载中...
 
   



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

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