求助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,我该怎么该才行