首先在你的父窗體添加將更新標籤的屬性。
public string LabelonParent {
get { return label1.Text;}
set { label1.Text=value;}
}
現在添加事件的方法,將顯示在子窗體子窗體
private void button1_Click(object sender, EventArgs e)
{
ChildClass form = new ChildClass();
DialogResult result = form.ShowDialog(this);
}
添加TextChanged事件的方法。
private void textBox1_TextChanged(object sender, EventArgs e)
{
((ParentClass)this.Owner).LabelonParent = textBox1.Text;
}
你甚至可能要添加一個formload事件方法與label1.Text填充textBox1的
private void ChildClass_Load(object sender, EventArgs e)
{
textBox1.Text = ((ParentClass)this.Owner).LabelonParent;
}
你可以改變文本框的屬性修改器或標籤公共爲了你訪問它像((MyForm)this.Parent).txtMyTextBox.Text =「」; – Jade