All parenting jokes aside, I have a general purpose status strip on my parent form that contains a progress bar and a few labels.
Occasionally a child form will execute a command that could be tracked on the status bar so my users don't think that the program is hanging...
I searched around and this topic seems to be open for quite a bit of debate. Some say use delegates, some say to set properties and some say to simply set the value of the control by name.
What's your thoughts? I'm looking for something that will be easy to update and maintain as well as easy to implement as a parent form can have multiple child forms.
Here are the suggestions I have run across so far:
Simply type:
this.ParentForm.Controls["label1"].Text="HI..."
Seems sloppy though and probably a nightmare to keep track of.
The other option, which might be the best -- but not sure, is from the DaniWeb web site: Update label text from another thread.
And finally this:
//IN THE CHILD FORM (MDIChild)
private void button1_Click(object sender, EventArgs e)
{
MDIParent oParent = ParentForm as MDIParent;
oParent.ChangeParentText = "My cool text";
}
//IN THE PARENT FORM (MDIParent)
public string ChangeParentText
{
get
{
return label1.Text;
}
set
{
label1.Text = value;
}
}
Any suggestions? What would be the preferred method for achieving this?