Cool effect, it is worthwhile to learn well ha.
To reset the Toolbox:
Create a new WinForm program with the project name Testdockpanelcontrol. Select the Form1 form after selecting the toolbox--->> new add tab named Weifenluo--->> right--->> select--->> browse---
>>weifenluo.winformsui.docking.dll--->> OK. The DockPanel control appears in the toolbox at this time. The above steps simply add the DockPanel control to the toolbox.
Next look at how the docking effect of the DockPanel control is implemented.
Main form settings: (Form1 form default is main form)
Form1 property settings for a form
Set the Text property of the form to the main form on the original Form1 form, and the IsMdiContainer property to True is to set the MDI program (in order to experience the presentation of the DockPanel control). FormBorderStyle set to
Fixedsingle,startposition set to Centerscreen,windowstate is set to maximized.
Form1 control layout for a form
Drag and drop the MenuStrip control and the DockPanel control under the Toolbox onto the form, setting the Dock property of the DockPanel control to fill. Set the value of the submenu options for the MenuStrip as shown in:
Docking form setup (Formdock is a subform):
Add a new WinForm form named Formdock, set the text value to be a docked form, and a size value of 207,382 where the value is not unique depending on the actual need.
Main point: Modify the form in code to inherit from Dockcontent, to add a using WeifenLuo.WinFormsUI.Docking namespace
Modify the previous code:
Public Partial class formdock:form{ public formdock () { InitializeComponent (); }}
Modified code:
Public Partial class formdock:D ockcontent{ public formdock () { InitializeComponent (); }}
Return to the main form Form1 form, display the form you want to dock in the Form1 form (formdock)
The code is as follows:
//Bottom Private voidBottomtoolstripmenuitem_click (Objectsender, EventArgs e) {formdock frm=NewFormdock (); frm. Text="Bottom Docking"; frm. Show ( This. DockPanel1); frm. Dockto ( This. DockPanel1, Dockstyle.bottom); } //Full Screen Private voidFilltoolstripmenuitem_click (Objectsender, EventArgs e) {formdock frm=NewFormdock (); frm. Text="Full-screen docking"; frm. Show ( This. DockPanel1); frm. Dockto ( This. DockPanel1, DockStyle.Fill); } //left Private voidLefttoolstripmenuitem_click (Objectsender, EventArgs e) {formdock frm=NewFormdock (); frm. Text="Left docking"; frm. Show ( This. DockPanel1); frm. Dockto ( This. DockPanel1, DockStyle.Left); } //None Private voidNonetoolstripmenuitem_click (Objectsender, EventArgs e) {formdock frm=NewFormdock (); frm. Text="NONE"; frm. Show ( This. DockPanel1); frm. Dockto ( This. DockPanel1, Dockstyle.none); } //Right Private voidRighttoolstripmenuitem_click (Objectsender, EventArgs e) {formdock frm=NewFormdock (); frm. Text="Right Docking"; frm. Show ( This. DockPanel1); frm. Dockto ( This. DockPanel1, Dockstyle.right); } //Top of Private voidToptoolstripmenuitem_click (Objectsender, EventArgs e) {formdock frm=NewFormdock (); frm. Text="Top Docking"; frm. Show ( This. DockPanel1); frm. Dockto ( This. DockPanel1, Dockstyle.top); }
The above is the whole operation of using the DockPanel control to dock the form.
As shown below:
The DockPanel control can also drag and drop subforms, and drag and drop the form into the top left and right inferior positions
Just set the AllowDrop of the DockPanel control to True. as shown below;
Use WeiFenLuo.WinFormsUI.Docking.dll in C # for window docking effects