Winform中DockPanel的使用教程及WeifenLuo.WinFormsUI.Docking.dll的用法

來源:互聯網
上載者:User

WeiFenLuo.WinFormsUI.Docking.dll是開源項目DockPanel Suite的一個類庫,可實現像Visual Studio的視窗停靠、拖拽等功能。WeifenLuo.WinFormsUI.Docking是一個很強大的介面布局控制項,可以儲存自訂的布局為XML檔案,可以載入XML設定檔。DockPanel中提供了幾個可用的類,重要的有兩個:DockPanel和DockContent。DockPanel是從Panel繼承出來的,用於為可浮動的dock的子視窗提供進行浮動和dock的場所;DockContent是從Form類中繼承出來的,用於提供可浮動的視窗基類。也就是說,DockContent對象可以在DockPanel對象中任意貼邊、浮動、TAB化等。

1、建立WinForm表單

2、修改WinForm表單內容

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

3、為MainForm表單添加功能表列

4、解決方案管理器-->添加引用-->瀏覽-->WeifenLuo.WinFormsUI.Docking.dll

5、工具箱-->選擇項...-->.Net Framework組件-->瀏覽-->WeifenLuo.WinFormsUI.Docking.dll

6、拖動工具箱中的DockPanel控制項到MainForm表單,拖動時如出現如下錯誤:


則 項目屬性對話方塊-->應用程式-->目標框架-->.Net Framework 4,即可解決

7、設定DockPanel控制項Dock屬性為Fill

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

8、添加兩個WinForm表單,分別為DockPanelFormMain和DockPanelFormSide,在表單的代碼中修改兩表單均繼承自DockContent,並修改其FormBorderStyle屬性為Fixed3D,設定DockPanelFormMain的BackColor屬性為White;

9、在MainForm的Load事件中添加如下代碼:

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、程式運行效果如下所示:



DockPanel WeifenLuo.WinFormsUI.Docking.dll的用法

基本架構

主表單建立

建立WinForm->添加引用WeifenLuo.WinFormsUI.Docking.dll
重新命名WinForm為MainWnd作為測試主視窗,設定MainWnd.IsMdiContainer=True;
由於引用WeifenLuo.WinFormsUI.Docking.dll時已經將控制項添加入工具箱,在工具箱中拖出DockPanel放到MainWnd上並設定DockPanel.Dock=Fill

至此主表單建立完畢

停靠表單建立

添加WinForm表單Dock1;
在該表單的代碼中修改表單繼承於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.在MainWnd中添加Load事件響應代碼來建立停靠視窗

private void MainWnd_Load(object sender, EventArgs e){    Dock1 dock1 = new Dock1();    dock1.Show(this.dockPanel1,  WeifenLuo.WinFormsUI.Docking.DockState.DockLeft);}

4.編譯產生,一個簡單的有停靠視窗的WinForm產生


5. 編譯產生,組合架構

相關關鍵詞:
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.