Http://hi.baidu.com/ivanbobo/blog/item/63571d1744ea941bc83d6ddd.html
Declare the parent window object in the Child Window. For example, if the parent window is mdiparent1 and the Child Window is MDI, you only need to call the parent window to declare the object, the method is as follows:
Public partial class MDI: Form
{
Public Delegate void posttext (string text );
Public event posttext pt;
Public MDI ()
{
Initializecomponent ();
}
Private void mdi_activated (Object sender, eventargs E)
{
Mdiparent1 mdiform = (mdiparent1) This. mdiparent;
Mdiform. statusstrip. items [0]. Text = This. Text; // when the parent form variable is public, it is easier to directly set
}
}
(Note) in this case, the statusstrip of the parent form is changed to public. In this case, the setting is simpler. In general, the control of the parent form is private, in this case, use the delegate to define the delegate in the MDI
Public partial class MDI: Form
{
Public Delegate void posttext (string text );
Public event posttext pt;
Public MDI ()
{
Initializecomponent ();
}
Private void mdi_activated (Object sender, eventargs E)
{
Mdiparent1 mdiform = (mdiparent1) This. mdiparent;
Mdiform. gettext (this. Text); // The parent form controls are usually private and delegated
}
}
Code in mdiparent1:
Public partial class mdiparent1: Form
{
Private int childformnumber = 0;
Public mdiparent1 ()
{
Initializecomponent ();
}
Private void shownewform (Object sender, eventargs E)
{
// Create a new instance for this subform.
Mdiapplication. MDI childform = new mdiapplication. MDI ();
// The child form of the MDI form before the form is displayed.
Childform. mdiparent = this;
Childform. windowstate = formwindowstate. maximized;
Childform. Text = "window" + childformnumber ++;
Childform. Show ();
Childform. Pt + = new MDI. posttext (gettext );
}
Public void gettext (string text)
{
This. statusstrip. items [0]. Text = text;
}
}
}