Reputation: 419
I have a form, which has a panel which has a form open inside it.
I wish to be able to read data from the child form on the parent.
private void NewSwitch_Load(object sender, EventArgs e)
{
newChild = new EnterSedol();
newChild.TopLevel = false;
newChild.AutoScroll = true;
panel1.Controls.Add(newChild);
newChild.Show();
}
private void GetValueFromChildButton(object sender, EventArgs e)
{
textBox1.Text = //What here??
}
Thanks
Upvotes: 0
Views: 699
Reputation: 10376
If there is possible many forms in your panel, then you can iterate throught them with Controls collection of your panel1. But you have to know how to destinguish them. For exaqmple:
foreach (var frm in panel1.Controls)
if (frm is EnterSedol &&
/*frm is target form, for example there is needed tag...*/ )
textBox1.Text = (frm as EnterSedol).GetData(); //Do your stuff
Upvotes: 0
Reputation: 81610
Since it looks like newChild isn't declared from inside the load method, you should be able to reference it directly:
textBox1.Text = newChild.ButtonValue;
If trying to reference controls inside the newChild form, either make the controls accessible, or make Properties in the EnterSedol object that will retrieve that information for you.
In your EnterSedol class:
public string ButtonValue {
get { return button1.Text; }
}
Upvotes: 1