1、下载WeifenLuo.WinFormsUI.Docking.dll.
2、新建WinForm窗体Form1,将其IsMdiContainer属性设置为True;
3、添加引用-->浏览-->WeifenLuo.WinFormsUI.Docking.dll.
4、视图-->工具箱-->选择项...-->.Net Framework组件-->浏览-->WeifenLuo.WinFormsUI.Docking.dll.
此时工具箱会增加DockPannel控件,拖动工具箱中的DockPanel控件到Form1窗体,并将其Dock属性设置为Fill.
5、再新建WinForm窗体Form2,继承DockContent,添加代码WeifenLuo.WinFormsUI.Docking.
6、再Form1添加以下代码
public Form1() { InitializeComponent(); var f2 = new Form2() { TabText = "Document" }; f2.Show(this.dockPanel1, DockState.Document); f2 = new Form2() { TabText = "DockLeft" }; ; f2.Show(this.dockPanel1, DockState.DockLeft); f2 = new Form2() { TabText = "DockRight" }; ; f2.Show(this.dockPanel1, DockState.DockRight); f2 = new Form2() { TabText = "DockBottom" }; ; f2.Show(this.dockPanel1, DockState.DockBottom); f2 = new Form2() { TabText = "DockLeftAutoHide" }; ; f2.Show(this.dockPanel1, DockState.DockLeftAutoHide); f2 = new Form2() { TabText = "Float" }; ; f2.Show(this.dockPanel1, DockState.Float); }
7、运行效果图如图所示