编写计算器时为什么显示输入字符串的格式不正确?

用的mfc2010窗体编写的简易计算器

加减乘除都没问题,做到了平方和开方时总是报错运行不了...从加法开始的代码如下: private void button11_Click(object sender, EventArgs e)
{
ysfs = 1;
temp1 = Convert.ToDouble(textBox1.Text);
textBox2.Text = "+";
textBox1.Text = " ";
} //+

    private void button12_Click(object sender, EventArgs e)
    {
        ysfs = 2;
        temp1 = Convert.ToDouble(textBox1.Text);
        textBox2.Text = "-";
        textBox1.Text = " ";
    }
    //-
    private void button13_Click(object sender, EventArgs e)
    {
        ysfs = 3;
        temp1 = Convert.ToDouble(textBox1.Text);
        textBox2.Text = "*";
        textBox1.Text = " ";
    } //*

    private void button14_Click(object sender, EventArgs e)
    {
        ysfs = 4;
        temp1 = Convert.ToDouble(textBox1.Text);
        textBox2.Text = "/";
        textBox1.Text = " ";
    } ///
    private void button17_Click(object sender, EventArgs e)
    {
        ysfs = 5;
        temp1 = Convert.ToDouble(textBox1.Text);
        textBox2.Text = "²";
        textBox1.Text = " ";
    } //平方
    private void button20_Click(object sender, EventArgs e)
    {
        double temp2 = Convert.ToDouble(textBox1.Text);
        switch (ysfs)
        {
            case 1:
                textBox1.Text = (temp1 + temp2).ToString();
                break;
            case 2:
                textBox1.Text = (temp1 - temp2).ToString();
                break;
            case 3:
                textBox1.Text = (temp1 * temp2).ToString();
                break;
            case 4:
                textBox1.Text = (temp1 / temp2).ToString();
                break;
            case 5:
                textBox1.Text = (Math.Pow(temp1, 2)).ToString();
                break;
            case 6:
                textBox1.Text = Math.Sqrt(temp1).ToString();
                break;
        }
    }//等于![图片说明](https://img-ask.csdn.net/upload/201812/28/1545994424_745007.png)

1个回答

mfc2010个鬼,这是C#的程序。输入字符串的格式不正确,说明文本框里的内容不是合法的数字不能转换为double

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问