我正在制作一个 Windows 窗体项目,并且在将动态生成的控件值传递给另一个窗体的正常控件值时遇到了困难。
我的代码是:
int c = 0;
int p = 0;
private void button1_Click(object sender, EventArgs e)
{
panel1.VerticalScroll.Value = VerticalScroll.Minimum;
// panel1.HorizontalScroll.Value = HorizontalScroll.Minimum;
ComboBox txtRun3 = new ComboBox();
txtRun3.Name = "txtDynamic" + c++ ;
txtRun3.Location = new Point(30, 18 + (30 * c))
panel1.Controls.Add(txtRun3);
txtRun3.Focus();
}
private void button2_Click(object sender, EventArgs e)
{
Form4 f4 = new Form4();
Button bt = sender as Button;
ComboBox cb2 = bt.Tag as ComboBox;
f4.Combo.Text = bt.Text;
}
我收到错误消息:
“对象引用未设置为对象的实例。”