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