| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1941 人关注过本帖
标题:这个程序按加号减号乘号除号没反应,为什么啊???
只看楼主 加入收藏
molong1989
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2010-3-21
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:3 
这个程序按加号减号乘号除号没反应,为什么啊???
按数字键和enter就行,但是加号减号乘号除号没反应,谁帮我看一下??

namespace cal
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        double num1=0, num2=0, result=0;
        bool point;
        string op;
        private void Form1_Load(object sender, EventArgs e)
        {
            textBox1.Text = "0.";
            
            textBox1.TextAlign = HorizontalAlignment.Right;
        }
        public void getnumber(int num)
        {
            if (point)
            { textBox1.Text = textBox1.Text + num; }
            else
            {
                if (textBox1.Text == "0.")
                { textBox1.Text = num + "."; }
                else
                {
                    textBox1.Text = textBox1.Text.Substring(0, textBox1.Text.Length - 1) + num + ".";
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            getnumber(1);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            getnumber(2);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            getnumber(3);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            getnumber(4);
        }

        private void button5_Click(object sender, EventArgs e)
        {
            getnumber(5);
        }

        private void button6_Click(object sender, EventArgs e)
        {
            getnumber(6);
        }

        private void button7_Click(object sender, EventArgs e)
        {
            getnumber(7);
        }

        private void button8_Click(object sender, EventArgs e)
        {
            getnumber(8);
        }

        private void button9_Click(object sender, EventArgs e)
        {
            getnumber(9);
        }

        private void button10_Click(object sender, EventArgs e)
        {
            getnumber(0);
        }

        private void buttonpoint_Click(object sender, EventArgs e)
        {
            point = true;
        }

        private void buttonadd_Click(object sender, EventArgs e)
        {
            op = "add";
            num1 = double.Parse(textBox1.Text);
            textBox1.Text = "0.";
            point = false;
            textBox1.Focus();
        }

        private void buttonsub_Click(object sender, EventArgs e)
        {
            op = "sub";
            num1 = double.Parse(textBox1.Text);
            textBox1.Text = "0.";
            point = false;
        }

        private void buttonmul_Click(object sender, EventArgs e)
        {
            op = "mul";
            num1 = double.Parse(textBox1.Text);
            textBox1.Text = "0.";
            point = false;
        }

        private void buttondiv_Click(object sender, EventArgs e)
        {
            op = "div";
            num1 = double.Parse(textBox1.Text);
            textBox1.Text = "0.";
            point = false;
        }

        private void buttonclear_Click(object sender, EventArgs e)
        {
            num1 = 0;
            num2 = 0;
            textBox1.Text = "0.";
        }

        private void buttonresult_Click(object sender, EventArgs e)
        {
            num2 = double.Parse(textBox1.Text);
            switch (op)
            {
                case "add":
                    result = num1 + num2;
                    textBox1.Text = result.ToString();
                    break;
                case "sub":
                    result = num1 - num2;
                    textBox1.Text = result.ToString();
                    break;
                case "mul":
                    result = num1 * num2;
                    textBox1.Text = result.ToString();
                    break;
                case "div":
                    if (num2 == 0)
                    {
                        textBox1.Text = "除数不能为0!";
                    }
                    else
                    {
                        result = num1 / num2;
                        textBox1.Text = result.ToString();
                        
                    }
                    break;
            }
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            switch((Keys)e.KeyChar)
            {
                case Keys.D1: button1_Click(sender, e); break;
                case Keys.D2: button2_Click(sender, e); break;
                case Keys.D3: button3_Click(sender, e); break;
                case Keys.D4: button4_Click(sender, e); break;
                case Keys.D5: button5_Click(sender, e); break;
                case Keys.D6: button6_Click(sender, e); break;
                case Keys.D7: button7_Click(sender, e); break;
                case Keys.D8: button8_Click(sender, e); break;
                case Keys.D9: button9_Click(sender, e); break;
                case Keys.D0: button10_Click(sender, e); break;
                case Keys.Add: this.buttonadd.PerformClick(); break;
                case Keys.Subtract: buttonsub_Click(sender, e); break;
                case Keys.Multiply: buttonmul_Click(sender, e); break;
                case Keys.Divide: buttondiv_Click(sender, e); break;
                case Keys.Enter: buttonresult_Click(sender, e); break;
                case Keys.C: buttonclear_Click(sender, e); break;


               
            }
            
        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            

        

        }

        
            

    }
}

[ 本帖最后由 molong1989 于 2010-3-21 19:27 编辑 ]
搜索更多相关主题的帖子: 加号 乘号 
2010-03-21 19:23
athenalux
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:河北石家庄
等 级:小飞侠
威 望:8
帖 子:975
专家分:2514
注 册:2008-11-26
收藏
得分:4 
上解决方案吧

QQ:81704464
2010-03-24 08:10
失落者
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:37
专家分:141
注 册:2008-3-22
收藏
得分:4 
看着头痛!

学C#的可进此QQ高级群,欢迎学生和工作人士
名称:C#的艺术
号码:89409630
2010-03-25 16:07
xiaxianlin
Rank: 2
等 级:论坛游民
帖 子:19
专家分:56
注 册:2010-3-12
收藏
得分:4 
确实头痛
2010-03-25 16:54
快速回复:这个程序按加号减号乘号除号没反应,为什么啊???
数据加载中...
 
   



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

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