- There are several classes available in the control DockPanel, two are important, one is DockPanel, the other is dockcontent,
DockPanel dockcontent is inherited from the form class and is used to provide a floating window base class. That is to say: The Dockcontent object can be arbitrarily welt in the DockPanel object, floating, tab, and so on.
- Browse->weifenluo.winformsui.docking.dll, add Reference, reference.
- Toolbox, right-click Options->.net Components, browse->weifenluo.winformsui.docking.dll-> the toolbox appears dockpanel.
- Drag dockpanel onto form FORM1, set dock properties, I set: Fill. Form Properties Ismdicontainer:true.
- Modify the form in code to inherit from Dockcontent. public partial class Form2:dockcontent
- In the main form:
Public Partial classform1:dockcontent {//child Form PrivateFrmcustomer Frmcustomer =NewFrmcustomer (); PrivateB_employee employee =NewB_employee (); PublicForm1 () {InitializeComponent (); Frmcustomer.show ( This. DockPanel1); Employee. Show ( This. DockPanel1); System.Threading.Thread.Sleep ( -); } Private voidForm1_Load (Objectsender, EventArgs e) {Form2 frm=NewForm2 (); frm. Show ( This. DockPanel1); //form Form2 Add to left edge of main formfrm. Dockto ( This. Dockpanel1,dockstyle.left); }}
- Add a right-click event to the main form, set DockPanel Contentmenuscrip to drag Menuscrip, form to add
/// <summary> ///Close all Forms/// </summary> /// <param name= "Sender" ></param> /// <param name= "E" ></param> Private voidMenu_window_closeall_click (Objectsender, EventArgs e) {closealldocuments (); } Public voidclosealldocuments () {if(dockpanel1.documentstyle==documentstyle.systemmdi) {foreach(Form forminchMdichildren) {form. Close (); } } Else{idockcontent[] documents=Dockpanel1.documentstoarray (); foreach(Idockcontent contentinchdocuments) {content. Dockhandler.close (); } } } /// <summary> ///Close Other Forms/// </summary> /// <param name= "Sender" ></param> /// <param name= "E" ></param> Private voidMenu_window_closeother_click (Objectsender, EventArgs e) { if(Dockpanel1.documentstyle = =documentstyle.systemmdi) {Form Activemdi=Activemdichild; foreach(Form forminchMdichildren) { if(Form! =Activemdi) {form. Close (); } } } Else { foreach(Idockcontent documentinchDockpanel1.documentstoarray ()) { if(!document. dockhandler.isactivated) {document. Dockhandler.close (); } } } } /// <summary> ///Find Form/// </summary> /// <param name= "text" ></param> /// <returns></returns> PrivateDockcontent Finddocument (stringtext) { if(Dockpanel1.documentstyle = =documentstyle.systemmdi) {foreach(Form forminchMdichildren) { if(Form. Text = =text) { returnForm asdockcontent; } } return NULL; } Else { foreach(Dockcontent contentinchdockpanel1.documents) {if(content. dockhandler.tabtext==text) { returncontent; } } return NULL; } } PublicDockcontent Showcontent (stringcaption, Type formtype) {dockcontent frm=Finddocument (caption); if(frm==NULL) { //frm = Childwinmanagement.loadmdiform (Portal.gc.MainDialog, FormType) as dockcontent;} frm. Show ( This. DockPanel1); frm. BringToFront ();//bring the control to the front returnfrm; }
Learn WinForm third-party interface WeiFenLuo.winFormsUI.Docking.dll