my code:
in parent_Form:
public parent_Form()
{
InitializeComponent();
}
private void button_Click(object sender, EventArgs e)
{
child ch = new child();
ch.MdiParent = this;
ch.Show();
}
public string label
{
set
{
开发者_如何学Python textBox1.Text = value;
}
}
in child form:
public child()
{
InitializeComponent();
}
private void write_button_Click(object sender, EventArgs e)
{
parent_Form paren = new parent_Form();
paren.label = "i am vietnamese";
}
but "i am vietnamese" doesn't display on textbox1 (it is on parent winform)
This line:
parent_Form paren = new parent_Form();
Is creating a new parent_Form which is never shown. You need to reference the actual parent like so:
((parent_Form)MdiParent).label = "i am vietnamese";
JRoughan's solution should work. Make sure you have the button click handler properly specified. Set a breakpoint in the handler to make sure it is being executed when you click the button. I tested this and it works.
public child()
{
InitializeComponent();
}
private void write_button_Click(object sender, EventArgs e)
{
parent_Form paren = ((parent_Form)MdiParent);
paren.label = "i am vietnamese";
}
精彩评论