专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > WinForm

WinForm界面格局控件WeifenLuo.WinFormsUI.Docking"的使用 (二)

发布时间:2011-06-23 13:53:54 文章来源:www.iduyao.cn 采编人员:星星草
WinForm界面布局控件WeifenLuo.WinFormsUI.Docking"的使用 (二)

WinForm界面布局控件WeifenLuo.WinFormsUI.Docking"的使用

()

编写人:CC阿爸

 

2015-1-29

 

今天我想与大家继续一起分享这一伟大的控件。有兴趣的同学,可以一同探讨与学习一下,否则就略过吧。

 

1.    DockPanel的一点点改进:

在浏览网上的一些技术文章发现,的确有些地方还是可以进一步改进,如当双击Tab时,原先是直接把当前Tab所表示的这个窗体,从主窗体的框架上分离现来,成为一个浮动的窗体。这不是我们想要的,有些同学修改源代码,把它改成了双击关闭。(测试Ok

 

以下链接为官方共享代码的出处,大家可以利用svn下载到最新的代码。所有的修改全部建立在源代码基础上的

http://sourceforge.net/projects/dockpanelsuite

 

双击关闭标签代码 主要是修改 DockPaneStripBase.cs 类里的protected override void WndProc(ref Message m)函数 代码如下

 

DockPaneStripBase.cs WndProc方法里,对于左键双击消息重新作了处理(下面注释掉的一行是原先的写法,它下面那行是改的):

 [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; //这句表示窗口还原初始大小并且脱离任何停靠
                    if (content.DockHandler.HideOnClose)
                        content.DockHandler.Hide();//隐藏
                    else
                        content.DockHandler.Close(); //关闭        
                }
 
                return;
            }
            base.WndProc(ref m);
            return;

        } 

2、很多窗体都在Tab中有个右键菜单,右击的里面有关闭,所以最好继承一下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(9822);
            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(9822);
            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(9822);
            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(9926);
            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++;
                }
            }
        }

}

以下为其它同学编写有关该控件的技术文档,供大家参考

http://www.cnblogs.com/luomingui/archive/2013/09/19/3329763.html

http://blog.csdn.net/dqvega/article/details/7594923

 

以下是修改后的dll供大家下载:

http://download.csdn.net/detail/shilei07068124/4506742

 

欢迎加入技术分享群

 

友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: