透過 nuget 安裝 V3.0.6 後,可以在 VS 工具箱內看見綠框這三個選項 (DockPanel、VisualStudioToolStripExtender 和 VS2005Theme),另外 DockPanel Suite 還有其他 Theme 可以安裝,只安裝 VS2015 Theme (橘框)
using WeifenLuo.WinFormsUI.Docking;
namespace DockSample
{
public partial class frmDock : DockContent
{
public frmDock()
{
InitializeComponent();
}
}
}
把 DockPanel 拉到 Form 內 (以本例來說,是 frmMain Form) 並進行下面設定
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
namespace DockSample
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
// frmMain 必須開啟 IsMdiContainer
this.IsMdiContainer = true;
// 設定 DockPanel 置中
dockPanel.Dock = DockStyle.Fill;
// 不允許使用者移動 DockPanel 內視窗 (Form)
dockPanel.AllowEndUserDocking = false;
// 設定 DockPanel Theme
dockPanel.Theme = new VS2015BlueTheme();
// 根據 DockState 把 frmDock 釘在 frmMain.DockPanel 上
frmDock frmDocument = new frmDock() { TabText = "Document" };
frmDocument.Show(this.dockPanel, DockState.Document);
frmDock frmDockLeft = new frmDock() { TabText = "DockLeft" }; ;
frmDockLeft.Show(this.dockPanel, DockState.DockLeft);
frmDock frmDockRight = new frmDock() { TabText = "DockRight" }; ;
frmDockRight.Show(this.dockPanel, DockState.DockRight);
frmDock frmDockBottom = new frmDock() { TabText = "DockBottom" }; ;
frmDockBottom.Show(this.dockPanel, DockState.DockBottom);
frmDock frmDockLeftAutoHide = new frmDock() { TabText = "DockLeftAutoHide" }; ;
frmDockLeftAutoHide.Show(this.dockPanel, DockState.DockLeftAutoHide);
frmDock frmFloat = new frmDock() { TabText = "Float" }; ;
frmFloat.Show(this.dockPanel, DockState.Float);
}
}
}
執行效果
沒有留言:
張貼留言