0
我在GroupBox内有12个文本框和12个标签。GroupBox内的TextBox事件处理程序
当价格输入到任何文本框中时,我想要计算税额并显示在此文本框旁边的标签中。
我已经编写了计算税款的代码,但仅在第一个标签labelTax01
中可见。
我的代码清单如下:
public void Form1_Load(object sender, EventArgs e)
{
foreach (Control ctrl in groupBoxPrice.Controls)
{
if (ctrl is TextBox)
{
TextBox price= (TextBox)ctrl;
price.TextChanged += new EventHandler(groupBoxPrice_TextChanged);
}
}
}
void groupBoxPrice_TextChanged(object sender, EventArgs e)
{
double output = 0;
TextBox price= (TextBox)sender;
if (!double.TryParse(price.Text, out output))
{
MessageBox.Show("Some Error");
return;
}
else
{
Tax tax = new Tax(price.Text); // tax object
tax.countTax(price.Text); // count tax
labelTax01.Text = (tax.Tax); // ***help*** ///
}
}
因此每个文本框旁边都有一个标签,对吧? – Badiparmagi