Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Communication between mdi forms 1

Status
Not open for further replies.

altor

Programmer
Nov 30, 2004
2
0
0
CA
I would like to know how to communicate between mdi forms, especially how to send a string from a mdichild form to the mdiparent form.

Thanks.
 
Since forms are objects, all you need to send a message (call a method, set a property) between them is a reference to the destination form.

MDI children have access to their parent via the MDIParent property. MDI parents have access to their child MDI forms via the MDIChildren collection.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Ok, it's easy to access a method or property of a mdichild form from the parent form but I'm not able to do the same in the other way.

For example, if I want to set the text property of the status bar of a mdiparent form, I can have this :

public class mdiParentForm : System.Windows.Forms.Form
{
...
public void SetStatusBar(string str)
{
statusbar1.Text = str;
}
}

And the following code from the mdichild form :
public class mdiChildForm : System.Windows.Forms.Form
{
...
public void SomeFunction()
{
this.mdiParent.SetStatusBar("Hello World");
}
}

This last code doesn't work because I can't access the SetStatusBar function from the mdichild.

What is the good way to do this ?

Thanks for your help.
 
There seems to be a bug with the MDIParent property. Try using the ordinary .Parent property.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
You can not access properties (or methods) of parent
through MDIParent unless you cast MDIParent to class
of your parent. MDIParent is Form and it doesn't have all
the methods (properties) of its subclasses.

regards

 
Star to ilumnissystems

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top