Shortcomings, please correct me!
What is MDI: I mean, I don't know.
MDI (Multiple document Interface) is the so-called multi-document interface, which corresponds to the single Document Interface (SDI), which was introduced by Microsoft from Microsoft Excel spreadsheet program under Windows 2.0, An Excel spreadsheet user sometimes needs to manipulate multiple tables at the same time, and MDI is a great convenience for this type of operation, resulting in an MDI program. --The mother explains this.
Create a new Windowform program. Get a form as our parent form. Drag into a menustrip space. Create a new form Frmchildren as our Subform
The code is as follows
Public Form1 () { InitializeComponent (); // set Form1 to MDI form, of course, in Form1 's IsMdiContainer property page you can set This true ; }
The event code for opening the subform in MenuStrip is as follows:
Private void Tsmiopenwindow_click (object sender, EventArgs e) { = Frmchildren.getwindow ( ); // Calling Methods This ;//Set child's parent form to the current form child . Show (); }
GetWindow () Where is this method? Of course it's written in the Frmchildren subform.
Public Partial classFrmchildren:form {PrivateFrmchildren ()//changed from public frmchildren to private Frmchildren{InitializeComponent (); } StaticFrmchildren FC =NULL; Create a static object Public StaticFrmchildren GetWindow () {//when the subform is not open or has been released. You can create a new form if(fc==NULL||FC. isdisposed) {FC=NewFrmchildren (); } returnFC; } }
The second method:
I think it's very simple. Open the subform directly under MenuStrip the write is OK
private void Tsmiopenwindow_click (object sender, EventArgs e)
{
#region Method Two application collects an open form, looking for it with an indexer, which is the Name property of the form
Method Two. If there is no child hull named Frmchildren, the instantiation is created. There is no difference between the formal practice and the previous, but more judgment.
if (application.openforms["frmchildren"] = = null)
{
Frmchildren child = new Frmchildren ();
Child. MdiParent = this;
Child. Show ();
}
Else//has a child hull named Frmchildren, which is directly show ()
{
application.openforms["Frmchildren"]. Show ();
}
#endregion
}