| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 791 人关注过本帖
标题:求助C#计算器问题
取消只看楼主 加入收藏
飞不起的小鸟
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2013-11-2
结帖率:0
收藏
已结贴  问题点数:10 回复次数:1 
求助C#计算器问题
代码如下
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 简单模拟计算器
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            textBox1.Text = "";
            label1.Text = "";

        }
        private void buttond_Click(object sender, EventArgs e)
        //单击数字命令按钮的事件处理程序
        {
            Button btn = (Button)sender;
            textBox1.Text = textBox1.Text + btn.Text;
        }

        private void button1_Click(object sender, EventArgs e)
        {

            Button btn = (Button)sender;
            textBox1.Text = textBox1.Text + btn.Text;

        }



        private void button2_Click(object sender, EventArgs e)
        {

            Button btn = (Button)sender;
            textBox1.Text = textBox1.Text + btn.Text;
        }

        private void button3_Click(object sender, EventArgs e)
        {

            Button btn = (Button)sender;
            textBox1.Text = textBox1.Text + btn.Text;
        }
        private void button4_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;
            textBox1.Text = textBox1.Text + btn.Text;
        }
        private void button5_Click(object sender, EventArgs e)
        {

            Button btn = (Button)sender;
            textBox1.Text = textBox1.Text + btn.Text;
        }



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

        private void button7_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;
            textBox1.Text = textBox1.Text + btn.Text;

        }

        private void button8_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;
            textBox1.Text = textBox1.Text + btn.Text;

        }

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

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

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

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

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

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

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

        private void button16_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;
            textBox1.Text = textBox1.Text + btn.Text;
        }
        private void buttonop_Click(object sender, EventArgs e)
        {
            
            Button btn = (Button)sender;
            
            if (btn.Name != "button12")//用户不单机“=”命令按钮
            {
                double x = Convert.ToDouble(textBox1.Text);
                string s = btn.Name;
                textBox1.Text = "";
                label1.Text = x.ToString();
            }
            else
            {
               
                if (label1.Text == "")
                    MessageBox.Show("输入不正确!!!", "信息提示", MessageBoxButtons.OK);
                else
                {
                    double y = Convert.ToDouble(textBox1.Text);
                    
                  
                    switch (s)//问题就在这个s,说上下文不存在名称s
                    {
                        case "button13"://用户刚前面单击“+”命令按钮
                            textBox1.Tex = (x + y).Tostring();
                            break;
                        case "button14"://用户刚前面单击“-”命令按钮
                            textBox1.Tex = (x - y).Tostring();
                            break;
                        case "button15"://用户刚前面单击“×”命令按钮
                            textBox1.Tex = (x * y).Tostring();
                            break;
                        case "button16"://用户刚前面单击“÷”命令按钮
                            if (y == 0)
                                MessageBox.Show("除零错误", "信息提示", MessageBoxButtons.OK);
                            else
                                textBox1.Tex = (x / y).Tostring();
                            break;
                    }
                    label1.Text = textBox1.Text;



                }
            }
  }
 }
  }
问题在那个变量s,我该怎么该才行
搜索更多相关主题的帖子: 计算器 private public 
2014-04-13 16:21
飞不起的小鸟
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2013-11-2
收藏
得分:0 
回复 4楼 步向巅峰
就是因为把它放到if外也会报错我才问的!!
2014-04-14 21:30
快速回复:求助C#计算器问题
数据加载中...
 
   



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

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