The usage of DockPanel in WinForm and WeifenLuo.WinFormsUI.Docking.dll

Source: Internet
Author: User
Tags response code

WeiFenLuo.WinFormsUI.Docking.dll is a class library of the Open source project DockPanel Suite, which enables the ability to dock, drag, and pull like Visual Studio Windows. WeifenLuo.WinFormsUI.Docking is a powerful interface layout control that can save custom layouts as XML files and can load XML configuration files. Several classes are available in the DockPanel, with two important: DockPanel and dockcontent. The DockPanel is inherited from the panel and is used to provide a place for floating and docking of the child windows of the floating dock; Dockcontent is inherited from the form class to provide a floating window base class. In other words, the Dockcontent object can be arbitrarily welt, floating, tab, etc. in the DockPanel object.

1. New WinForm Form

2. Modify WinForm Form Properties

This. IsMdiContainer = true;
This. Name = "MainForm";
This. Text = "MainForm";

3. Add menu bar for mainform form

4, Solution Manager--> Add Reference--> Browse-->weifenluo.winformsui.docking.dll

5. Toolbox--> Selection ...-->.net framework components--> browsing-->weifenluo.winformsui.docking.dll

6, drag the DockPanel control in the toolbox to the MainForm form, and drag when the following error occurs:


The Project Properties dialog box--> the application--> the target Framework-->.net framework 4 to resolve

7, set DockPanel Control Dock property to fill

This.dockPanel1.Dock = System.Windows.Forms.DockStyle.Fill;

8, add two WinForm forms, respectively Dockpanelformmain and dockpanelformside, and modify both forms in the form's code to inherit from Dockcontent. and modify its FormBorderStyle property to Fixed3D, set Dockpanelformmain BackColor property to White;

9, add the following code to the MainForm Load event:

Dockpanelformmain dockpanelmain1 = new dockpanelformmain ();
Dockpanelmain1.show (THIS.DOCKPANEL1);
dockpanelmain1.text =  "MainPanel1";
Dockpanelformmain dockpanelmain2 = new dockpanelformmain ();
Dockpanelmain2.show (THIS.DOCKPANEL1);
dockpanelmain2.text =  "MainPanel2";
Dockpanelformside dockpanelsideleft = new dockpanelformside ();
Dockpanelsideleft.show (This.dockpanel1, weifenluo.winformsui.docking.dockstate.dockleft);
dockpanelsideleft.text =  "Dockpanelleft";
Dockpanelformside dockpanelsideright = new dockpanelformside ();
Dockpanelsideright.show (This.dockpanel1, weifenluo.winformsui.docking.dockstate.dockright);
dockpanelsideright.text =  "Dockpanelright";
Dockpanelformside dockpanelsidebottom = new dockpanelformside ();
Dockpanelsidebottom.show (This.dockpanel1, weifenluo.winformsui.docking.dockstate.dockbottom); Dockpanelsidebottom.text =  "Dockpanelbottom"; 


10, the program operation effect as follows:



The use of DockPanel WeifenLuo.WinFormsUI.Docking.dll

Basic framework

Main form Build

New winform-> Add Reference WeifenLuo.WinFormsUI.Docking.dll
Rename WinForm for Mainwnd as the main test window, set mainwnd.ismdicontainer=true;
Because the control was added to the toolbox when referencing WeifenLuo.WinFormsUI.Docking.dll, drag the DockPanel onto the Mainwnd in the Toolbox and set Dockpanel.dock=fill

This is where the main form is built

Docking form Establishment

Add WinForm form Dock1;
Modify the form in the code of the form to inherit from Dockcontent

Using System;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Linq;
Using System.Text;
Using System.Windows.Forms;
Namespace Weifenluotest
{public
partial class Dock1:WeifenLuo.WinFormsUI.Docking.DockContent
{
   public Dock1 ()
{
InitializeComponent ();
}
}
}


3. Add the Load event response code to the Mainwnd to create a docking window

private void Mainwnd_load (object sender, EventArgs e)
{
Dock1 dock1 = new Dock1 ();
Dock1. Show (This.dockpanel1, WeifenLuo.WinFormsUI.Docking.DockState.DockLeft);
}

4. Compile generation, a simple WinForm with docked windows


5. Compile build, assemble frame

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.