Really, don't do that.
The first problem is that
ParentForm uxParent = new ParentForm();
Does not give you access to the actual parent - the
new
keyword is a clue here - it generates a new
instance of the parent form. If your parent form automatically creates an instance of the child form in it's constructor, your program will immediately crash because it will loop itself. To do anything like that, yoiu need access to teh actual instance of the parent form.
While that is available (as Kishor syas in his solution), it is a very bad idea to use it for something like this, because it ties the design of the two forms together so that neither one can exist without the other, and you cannot make changes to one without considering any possible effects on the other. This is very bad practice, and against the principles of OOP. This is why all form controls are declared private by default!
It's not difficult to do the job properly - all you have to do is create properties in the child form to supply the data to, create an event in the child form which says it needs the data, and handle the event in the parent:
Child form:
public string MyProperty
{
get { return myTextBox.Text; }
set { myTextBox.Text = value; }
}
public event EventHandler ReadyForData;
protected virtual void OnReadyForData(EventArgs e)
{
EventHandler eh = ReadyForData;
if (eh != null)
{
eh(this, e);
}
}
To signal you need the data, just call the method:
OnReadyForData(null);
In the parent form, add a handler when you construct the child instance:
frmChild myChildForm = new frmChild();
... Do your other child initialization
myChildForm.ReadyForData += new EventHandler(myChildForm_ReadyForData);
}
void myChildForm_ReadyForData(object sender, EventArgs e)
{
frmChild child = sender as frmChild;
if (child != null)
{
child.MyProperty = "Here is the new data";
}
}