在委托文本框(textbox1)中写入任何数字并在textbox2中显示表示委托率的结果时显示错误结果 [英] wrong result display when write any number in commission textbox (textbox1) and display result in textbox2 that represent commision rate
问题描述
问题
我的问题是无法在委托文本框(textbox1)中写入任何数字并在textbox2中显示结果佣金率
在textbox1中写佣金给我错误或奇怪的佣金率数字如图2所示。
如何正确显示 在textbox1中写佣金时的佣金率。
佣金率=(佣金/金额)* 100
我有3个文本框
I have 3 text boxes
textbox1:代表佣金
textbox1 : represent Commission
佣金=(金额*费率)/ 100
Commission=(amount * rate)/100
textbox2:代表佣金率
textbox2 : represent CommissionRate
佣金率=(佣金) /金额)* 100
CommissionRate=(Commission/amount)*100
txtLgAmount represent amount
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(textBox1.Text) && !string.IsNullOrEmpty(txtLgAmount.Text))
{
textBox2.Text = ((Convert.ToDecimal(textBox1.Text) / Convert.ToDecimal(txtLgAmount.Text))*100).ToString();
}
else
{
textBox2.Text = "";
}
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(textBox2.Text) && !string.IsNullOrEmpty(txtLgAmount.Text))
{
textBox1.Text = ((Convert.ToDecimal(txtLgAmount.Text)) * (Convert.ToDecimal(textBox2.Text) / 100)).ToString();
}
else
{
textBox1.Text = "";
}
}
推荐答案
尝试这样的事情:
bool f = false;
private void textBox1_TextChanged(object sender,EventArgs e)
{
if(f)return;
f = true;
跨度> 。 。 。设置textBox2的值
f = false;
}
private void textBox2_TextChanged(object sender,EventArgs e)
{
  if(f)return;
f = true;
跨度> 。 。 。设置textBox1的值
f = false;
}
bool f = false;
private void textBox1_TextChanged(object sender, EventArgs e)
{
if( f ) return;
f = true;
. . . set the value of textBox2
f = false;
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
if( f ) return;
f = true;
. . . set the value of textBox1
f = false;
}
这篇关于在委托文本框(textbox1)中写入任何数字并在textbox2中显示表示委托率的结果时显示错误结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!