C # How to call the control in the parent form of the MDI child form during development

Source: Internet
Author: User

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;
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.