当textBox2.Text和textBox1.Text为空时,我按=号就出错了
未处理的“System.FormatException”类型的异常出现在 mscorlib.dll 中。其他信息: 输入字符串的格式不正确。哪位大虾知道这是怎么回事namespace 计算机器
{
    public partial class 计算机器 : Form
    {
        public 计算机器()
        {
            InitializeComponent();
        }        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox2.Text == null || textBox1.Text == null)
            {
                return;
            }
            else
            {
                double a, b, c;
                a = double.Parse(textBox1.Text);
                b = double.Parse(textBox2.Text);                if (comboBox1.Text == "加")
                {
                    c = a + b;
                    textBox3.Text = c.ToString();
                }
                if (comboBox1.Text == "减")
                {
                    c = a - b;
                    textBox3.Text = c.ToString();
                }
                if (comboBox1.Text == "乘")
                {
                    c = a * b;
                    textBox3.Text = c.ToString();
                }
                if (comboBox1.Text == "除")
                {
                    c = a / b;
                    textBox3.Text = c.ToString();
                }
            }        }    }
}

解决方案 »

  1.   

    第一个问题自己搞定了
    再想问个问题
                if (textBox2.Text == null || textBox1.Text == null)
                {
                    return;
                }这里面如果要弹出一个消息框“不能为空!”
    该怎么做?
      

  2.   

               if (textBox2.Text == null || textBox1.Text == null) 
                { 
                    MessageBox.Show("不能为空!");
                    textBox2.Focus();
                    return; 
                } 
      

  3.   

    请问大家一个问题。
            private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
            {
                if (e.KeyChar.ToString() != "\b" && !(char.IsDigit(e.KeyChar)))
                {
                    e.Handled = true;
                }        }
    为什么我这样写之后,然后在textBox1中还是能输入英文呢,编译通过没有地方出错,很奇怪?
      

  4.   


    MessageBox.Show("不能为空!")
      

  5.   

    处理一下keydown事件,你查查msdn,keydown事件参数好像有个handled 属性,如果是非字符,把他设为 true 或者是 keypress 事件,懒的查,你自己看下