我使用C#中的List创建了动态文本框,我希望在创建文本框后立即执行事件
以下是我的代码。
private List<TextBox> txtTotalCost = new List<TextBox>();
private void btnMaterialAdd_Click(object sender, EventArgs e)
{
TextBox tbTotalCost = new TextBox();
tbTotalCost.Location = new Point(652, RowCount * 22);
tbTotalCost.Width = 60;
txtTotalCost.Add(tbTotalCost);
tbTotalCost.MouseClick += tbTotalCost_TextChanged;
panel1.Controls.Add(tbTotalCost);
}
void tbTotalCost_TextChanged(object sender, EventArgs e)
{
TextBox tb = (TextBox)sender;
TotalCost = CanadianCost * Qut;
tb.Text = TotalCost.ToString();
return;
}
我想生成或执行事件作为创建的文本框我现在想要鼠标单击或text_change。 并希望在
中显示两个整数的乘法我该怎么办?
答案 0 :(得分:2)
这样做:
private void btnMaterialAdd_Click(object sender, EventArgs e)
{
TextBox tbTotalCost = new TextBox();
tbTotalCost.Location = new Point(652, RowCount * 22);
tbTotalCost.Width = 60;
txtTotalCost.Add(tbTotalCost);
tbTotalCost.MouseClick += tbTotalCost_TextChanged;
panel1.Controls.Add(tbTotalCost);
tbTotalCost_TextChanged(tbTotalCost, null); // <-- this line.
}