0
当我尝试更改父窗体中的标签时,它给了我一个NullReferenceException。父母形式给予NullReferenceException
Form1中
public string LabelText
{
get
{
return label1.Text;
}
set
{
label1.Text = value;
}
}
private void Form1_Load(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.ShowDialog();
}
窗体2
private void button1_Click(object sender, EventArgs e)
{
((Form1)ParentForm).LabelText = textBox1.Text;
this.Close();
}
也许ParentForm为空? –
你还没有告诉Form2它有一个父窗体。这样做:'Form2 f2 = new Form2(this);' – Equalsk