日期:2014-05-17  浏览次数:20924 次

如何点击按钮执行两个函数?
C# code
public bool IsPositiveDouble(TextBox textBox)
        {
            if(Regex.IsMatch(textBox1.Text,"^[1-9]\\d*$") && Regex.IsMatch(textBox2.Text,"^[1-9]\\d*$")&&Regex.IsMatch(textBox3.Text,"^[1-9]\\d*$"))
            {
                textBox1.BackColor = Color.Green;
                textBox2.BackColor = Color.Green;
                textBox3.BackColor = Color.Green;
                return true;
            }
            else
            {
                textBox1.BackColor = Color.Red;
                textBox2.BackColor = Color.Red;
                textBox3.BackColor = Color.Red;
                MessageBox.Show("Error!");
                return false;
            }
        }

        public bool Volume(TextBox textBox)
        {
            double a = Convert.ToDouble(textBox1.Text.Trim());
            double b = Convert.ToDouble(textBox2.Text.Trim());
            double c = Convert.ToDouble(textBox3.Text.Trim());
            textBox4.Text = (a * b * c).ToString();
            return true;
        }

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


我想实现点击button1之后先执行IsPositiveDouble判断输入的数字,如果是的话就执行Volume,不是的话就提示一个MessageBox。请问这个应该怎么写?

------解决方案--------------------
C# code
if (IsPositiveDouble(this.textBox1))
    Volume(this.TextBox1);
else
    MessageBox.Show("...");

------解决方案--------------------
探讨

引用:
C# code
if (IsPositiveDouble(this.textBox1))
Volume(this.TextBox1);
else
MessageBox.Show("...");


对了。谢谢!
请教一下为什么是textbox1而不是textbox4?