MDI-only one child form can be set to pop up, and mdi-form to pop up

Source: Internet
Author: User

MDI-only one child form can be set to pop up, and mdi-form to pop up

For more information, see!

What is MDI? I don't know.

MDI (Multiple Document Interface) is a so-called multi-Document Interface, which corresponds to a single Document Interface (SDI ), it was introduced by Microsoft from the Microsoft Excel spreadsheet program in Windows 2.0. Excel spreadsheet users sometimes need to operate multiple copies at the same time, MDI provides great convenience for such operations on multiple tables, so an MDI program is generated. -- Du Niang explained this

Create a new WindowForm program. Get a form as our Parent form Parent. Drag a menustrip space. Create a new form FrmChildren as our child form

The Code is as follows:

Public Form1 () {InitializeComponent (); // set Form1 as an MDI form. Of course, you can set this. IsMdiContainer = true on the IsMdiContainer attribute page of Form1 ;}

The code for opening a subform event in menustrip is as follows:

Private void tsmiOpenWindow_Click (object sender, EventArgs e) {FrmChildren child = FrmChildren. getWindow (); // call method child. mdiParent = this; // set the parent form of child to the current form child. show ();}
Where is the GetWindow () method. Of course, it is written in the FrmChildren subform.
Public partial class FrmChildren: Form {private FrmChildren () // changed from public FrmChildren to private FrmChildren {InitializeComponent ();} static FrmChildren fc = null; create a static object public static FrmChildren GetWindow () {// when the child form is not enabled or has been released. You can create a new form if (fc = null | fc. IsDisposed) {fc = new FrmChildren () ;}return fc ;}}

Method 2:

I think it is very simple. It is OK to write it directly under the event that opens the sub-form in menustrip.

Private void tsmiOpenWindow_Click (object sender, EventArgs e)
{

# Region method 2 Application collects open forms and uses the indexer to find them, that is, the Name attribute of the form.
// Method 2. If there is no sub-hull whose Name is FrmChildren, instantiate it and create it. There is no difference from the previous formal practice, but there is more judgment.
If (Application. OpenForms ["FrmChildren"] = null)
{
FrmChildren child = new FrmChildren ();
Child. MdiParent = this;
Child. Show ();
}
Else // if there is a sub-hull named FrmChildren, show ()
{
Application. OpenForms ["FrmChildren"]. Show ();
}

# Endregion

}

 


C # net how to set a form as a child form of another MDI form

The first MDI main form
Form2 f = new Form2 ();
F. ShowDialog ();

Second form
Form3 f = new Form3 ();
F. MDIParent = Form1; // set the third form to the child form of the MDI main form
F. Show ();

C # Set a form as a child form of an MDI form

Child form frmson parent form frmdad
Find IsMidContainer in the parent form attribute and set it to True;
Double-click the parent form and write the following code in the frmdad_Load event:
Frmson fs = new frmson ();
Fs. MdiParent = this;
Fs. show ();

Related Article

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.