概述html
最近幾天一直在關注WinFrom方面的文章主要仍是園子裏伍華聰的博客,在看看咱們本身寫的項目差不忍賭啊,有想着提煉一下項目的公共部分,公共部分有分爲 界面,類庫兩方面,今天主要是把界面也先提煉提煉。框架
WeifenLuo.WinFormsUI.Docking + OutLookBar結合使用的效果圖ide
WeifenLuo.WinFormsUI.Docking修改記錄函數
從http://sourceforge.net/projects/dockpanelsuite上下載源碼新建DockContentEx文件並繼承WeifenLuo.WinFormsUI.Docking.DockContent在裏面加入ContextMenuStrip菜單工具並加入 關閉 所有關閉 除此以外所有關閉 三個菜單。項目結構以下工具
組件結構圖:佈局
源代碼以下:ui
/// <summary> /// 不少窗體都在Tab中有個右鍵菜單,右擊的裏面有關閉,因此最好繼承一下DockContent, /// 讓其它窗體只要繼承這個就有了這個右鍵菜單 /// </summary> public class DockContentEx : DockContent { //在標籤上點擊右鍵顯示關閉菜單 public DockContentEx( ) { System.Windows.Forms.ContextMenuStrip cms = new System.Windows.Forms.ContextMenuStrip(); // // tsmiClose // System.Windows.Forms.ToolStripMenuItem tsmiClose = new System.Windows.Forms.ToolStripMenuItem(); tsmiClose.Name = "cms"; tsmiClose.Size = new System.Drawing.Size(98, 22); tsmiClose.Text = "關閉"; tsmiClose.Click += new System.EventHandler(this.tsmiClose_Click); // // tsmiALLClose // System.Windows.Forms.ToolStripMenuItem tsmiALLClose = new System.Windows.Forms.ToolStripMenuItem(); tsmiALLClose.Name = "cms"; tsmiALLClose.Size = new System.Drawing.Size(98, 22); tsmiALLClose.Text = "所有關閉"; tsmiALLClose.Click += new System.EventHandler(this.tsmiALLClose_Click); // // tsmiApartFromClose // System.Windows.Forms.ToolStripMenuItem tsmiApartFromClose = new System.Windows.Forms.ToolStripMenuItem(); tsmiApartFromClose.Name = "cms"; tsmiApartFromClose.Size = new System.Drawing.Size(98, 22); tsmiApartFromClose.Text = "除此以外所有關閉"; tsmiApartFromClose.Click += new System.EventHandler(this.tsmiApartFromClose_Click); // // tsmiClose // cms.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { tsmiClose,tsmiApartFromClose,tsmiALLClose}); cms.Name = "tsmiClose"; cms.Size = new System.Drawing.Size(99, 26); this.TabPageContextMenuStrip = cms; } private void tsmiClose_Click(object sender, EventArgs e) { this.Close(); } private void tsmiALLClose_Click(object sender, EventArgs e) { DockContentCollection contents = DockPanel.Contents; int num = 0; while (num < contents.Count) { if (contents[num].DockHandler.DockState == DockState.Document) { contents[num].DockHandler.Hide(); } else { num++; } } } private void tsmiApartFromClose_Click(object sender, EventArgs e) { DockContentCollection contents = DockPanel.Contents; int num = 0; while (num < contents.Count) { if (contents[num].DockHandler.DockState == DockState.Document && DockPanel.ActiveContent != contents[num]) { contents[num].DockHandler.Hide(); } else { num++; } } } }雙擊關閉標籤代碼 主要是修改 DockPaneStripBase.cs 類裏的protected override void WndProc(ref Message m)函數 代碼以下this
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)] protected override void WndProc(ref Message m) { if (m.Msg == (int)Win32.Msgs.WM_LBUTTONDBLCLK) { base.WndProc(ref m); int index = HitTest(); if (DockPane.DockPanel.AllowEndUserDocking && index != -1) { IDockContent content = Tabs[index].Content; //if (content.DockHandler.CheckDockState(!content.DockHandler.IsFloat) != DockState.Unknown) // content.DockHandler.IsFloat = !content.DockHandler.IsFloat; //else // content.DockHandler.Close(); //實現雙擊文檔選項卡自動關閉if(content.DockHandler.HideOnClose) content.DockHandler.Hide();//隱藏 else content.DockHandler.Close(); //關閉 } return; } base.WndProc(ref m); return; }
我是這樣偷着寫代碼的。spa
插件的代碼使用的是OEA框架裏面代碼,Logging使用的是SuperSocket代碼。.net
1: 獲取指定目錄的全部DLL到內存。
2: 在ToolboxFrm界面中加入到OutLookBar控件並顯示出來。
WinForm界面開發之佈局控件"WeifenLuo.WinFormsUI.Docking"的使用
http://sourceforge.net/projects/dockpanelsuite
http://download.csdn.net/detail/luomingui/6290535
http://home.cnblogs.com/group/topic/54686.html
http://blog.csdn.net/dqvega/article/details/7594923