日期:2014-05-17 浏览次数:20907 次
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) { }
if (IsPositiveDouble(this.textBox1)) Volume(this.TextBox1); else MessageBox.Show("...");
------解决方案--------------------