Use WeiFenLuo.WinFormsUI.Docking.dll in C # for window docking effects

Source: Internet
Author: User

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

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.