概述
最近幾天一直在關注WinFrom方面的文章主要還是園子里伍華聰的博客,在看看我們自己寫的項目差不忍賭啊,有想着提煉一下項目的公共部分,公共部分有分為 界面,類庫兩方面,今天主要是把界面也先提煉提煉。
WeifenLuo.WinFormsUI.Docking + OutLookBar結合使用的效果圖
WeifenLuo.WinFormsUI.Docking修改記錄
從http://sourceforge.net/projects/dockpanelsuite上下載源碼新建DockContentEx文件並繼承WeifenLuo.WinFormsUI.Docking.DockContent在里面加入ContextMenuStrip菜單工具並加入 關閉 全部關閉 除此之外全部關閉 三個菜單。項目結構如下
組件結構圖:
源代碼如下:
/// <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)函數 代碼如下
[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; }
我是這樣偷着寫代碼的。
插件的代碼使用的是OEA框架里面代碼,Logging使用的是SuperSocket代碼。
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




![btn_download[1] btn_download[1]](/image/aHR0cHM6Ly9pbWFnZXMwLmNuYmxvZ3MuY29tL2Jsb2cvNTQzNDYvMjAxMzA5LzE5MjMyMDE4LTk3ZTFmNmNmNWM4ZTRlZWZhMWMxOWU4YzQ0ZTIwZjg5LnBuZw==.png)