问下高手 c#中 3个A,B,C textbox控件中输入数字相加不能超过100,
先输入A中数字,B的输入数字提示不能超过100-A,C中的数字不能超过100-A-B,当然可以先填入C或B顺序可变也要考虑,空值时也要排除报错求代码或方法!private...
先输入A中数字,B的输入数字提示不能超过100-A,C中的数字不能超过100-A-B,当然可以先填入C或B顺序可变也要考虑,空值时也要排除报错 求代码或方法!
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
}
功能实例,3个人分配比例,A,B,C3个人合计100% 展开
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
}
功能实例,3个人分配比例,A,B,C3个人合计100% 展开
2个回答
展开全部
感觉用 numericUpDown 控件好点,不用Covert那么多,三个 numericUpDown 的valuechange 都调用Test() 方法,8种可能已列出完,具体要怎么提示你慢慢改动咯
private void Test()
{
double a = (double)numericUpDown1.Value;
double b = (double)numericUpDown2.Value;
double c = (double)numericUpDown3.Value;
if (a == 0 && b == 0 && c == 0)//000
{
//
}
else if (a == 0 && b == 0 && c > 0)//001
{
this.label4.Text = string.Format("a < {0} b<{0}", 100.0 - a);
}
else if (a == 0 && b > 0 && c == 0)//010
{
this.label4.Text = string.Format("a < {0} c<{0}", 100.0 - a);
}
else if (a == 0 && b > 0 && c > 0)//011
{
this.label4.Text = string.Format("a < {0} ", 100.0 - b - c);
numericUpDown1.Value = Convert.ToDecimal(100.0 - b - c);
}
else if (a > 0 && b == 0 && c == 0)//100
{
this.label4.Text = string.Format("b < {0} c<{0}", 100.0 - a);
}
else if (a > 0 && b == 0 && c > 0)//101
{
this.label4.Text = string.Format("b < {0} ", 100.0 - a - c);
numericUpDown2.Value = Convert.ToDecimal(100.0 - a - c);
}
else if (a > 0 && b > 0 && c == 0)//110
{
this.label4.Text = string.Format("c<{0}", 100.0 - a - b);
numericUpDown3.Value = Convert.ToDecimal(100.0 - a - b);
}
else if (a > 0 && b > 0 && c > 0)//111
{
if (a+b+c>100)
{
MessageBox.Show("Test");
}
}
}
private void Test()
{
double a = (double)numericUpDown1.Value;
double b = (double)numericUpDown2.Value;
double c = (double)numericUpDown3.Value;
if (a == 0 && b == 0 && c == 0)//000
{
//
}
else if (a == 0 && b == 0 && c > 0)//001
{
this.label4.Text = string.Format("a < {0} b<{0}", 100.0 - a);
}
else if (a == 0 && b > 0 && c == 0)//010
{
this.label4.Text = string.Format("a < {0} c<{0}", 100.0 - a);
}
else if (a == 0 && b > 0 && c > 0)//011
{
this.label4.Text = string.Format("a < {0} ", 100.0 - b - c);
numericUpDown1.Value = Convert.ToDecimal(100.0 - b - c);
}
else if (a > 0 && b == 0 && c == 0)//100
{
this.label4.Text = string.Format("b < {0} c<{0}", 100.0 - a);
}
else if (a > 0 && b == 0 && c > 0)//101
{
this.label4.Text = string.Format("b < {0} ", 100.0 - a - c);
numericUpDown2.Value = Convert.ToDecimal(100.0 - a - c);
}
else if (a > 0 && b > 0 && c == 0)//110
{
this.label4.Text = string.Format("c<{0}", 100.0 - a - b);
numericUpDown3.Value = Convert.ToDecimal(100.0 - a - b);
}
else if (a > 0 && b > 0 && c > 0)//111
{
if (a+b+c>100)
{
MessageBox.Show("Test");
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询