【发布时间】:2015-08-28 11:39:11
【问题描述】:
我有一个 Windows 应用程序链接到一个数据库。当这个文本框的文本发生变化时,它应该从文本框中计算一些值。我写了,它工作正常,所有的,除了一个。如果 textBox2 中的文本小于 20,则计算正确,如果大于,则不再正确计算,我什至可以知道为什么会这样。自从我试图解决它以来已经有 2 天了,但什么也没有。任何人都可以得到它吗?
private void textBox1_TextChanged_1(object sender, EventArgs e)
{
int total = textBox1.Text.Length == 0 ? 0 : int.Parse(textBox1.Text);
textBox2.Text = total.ToString();
textBox7.Text = (total * 8).ToString();
}
private void textBox7_TextChanged_1(object sender, EventArgs e)
{
int ore_l = textBox7.Text == "" ? 0 : int.Parse(textBox7.Text);
int ore_n = textBox8.Text == "" ? 0 : int.Parse(textBox8.Text);
int t = ((ore_l - ore_n) / 8);
textBox2.Text = t.ToString();
}
private void textBox8_TextChanged_1(object sender, EventArgs e)
{
//it is correct
int ore_l = textBox7.Text == "" ? 0 : int.Parse(textBox7.Text);
int ore_n = textBox8.Text == "" ? 0 : int.Parse(textBox8.Text);
int t = ((ore_l - ore_n) / 8);
textBox2.Text = t.ToString();
//it isn't correct anymore
int ac = label14.Text.Trim() == "" ? 0 : int.Parse(label14.Text);
int zi_l = textBox1.Text.Trim() == "" ? 0 : int.Parse(textBox1.Text);
int zi_luc = textBox2.Text.Trim() == "" ? 0 : int.Parse(textBox2.Text);
int total = ac / zi_l * zi_luc;
textBox6.Text = total.ToString();
}
private void textBox6_TextChanged_1(object sender, EventArgs e)
{
int s = textBox4.Text == "" ? 0 : int.Parse(textBox4.Text);
int ac = label14.Text == "" ? 0 : int.Parse(label14.Text);
textBox5.Text = (ac + s).ToString();
}
private void textBox4_TextChanged(object sender, EventArgs e)
{
int b = label21.Text == "" ? 0 : int.Parse(label21.Text);
int sa = textBox1.Text == "" ? 0 : int.Parse(textBox1.Text);
int t = (b / sa + (75 / 100 * b / sa));
textBox10.Text = t.ToString();
int s = textBox4.Text == "" ? 0 : int.Parse(textBox4.Text);
int ac = label14.Text == "" ? 0 : int.Parse(label14.Text);
textBox5.Text = (ac + s).ToString();
}
用这个值测试它: ac = 1400 ; zi_l = 23 ; zi_luc = 23。所以:1400/23*23。应该是 1400,因为它是 int,实际上显示的是 1380。
P.S:由于文本更改并且值错误,因此不会发生这种情况。我分别尝试了一个按钮和方法onClick,结果是一样的。谢谢!
【问题讨论】:
标签: c# textbox calculator