C# WinForm 技巧八:界面开发之“WeifenLuo.WinFormsUI.Docking+OutLookBar” 使用

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控件并显示出来。

posted on   大西瓜3721  阅读(668)  评论(0编辑  收藏  举报

编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)

导航

点击右上角即可分享
微信分享提示