在伍华聪的博客中,看到布局控件"WeifenLuo.WinFormsUI.Docking",发现的确是一个非常棒的开源控件,用过的人都深有体会,该控件之强大、美观、不亚于商业控件。而且控件使用也是比较简单的今天在这里,我想与大家一起分这一伟大的控件。有兴趣的同学,可以一同探讨与学习一下,否则就略过吧。

一、引用方法:

1.建立一个WinForm工程,默认生成了一个WinForm窗体。

2.引用—>添加引用—>浏览—>weiFenLuo.winFormsUI.Docking.dll。

3.窗体属性IsMdiContainer:True。

4.工具箱—>右键—>选择项—>.net组件—>浏览—>weiFenLuo.winFormsUI.Docking.dll—>在工具箱出现dockPanel。

5.将dockPanel拖到窗体上,设置Dock属性,我设置的是:Fill。在这里要注意,在先增加菜单工具条,后增加dockpanel否则,会出现布局介面显示不全的问题。

以下为具体的设计介面:

左侧加入一窗体,并设计成outlookbar的样式。它其实也是在一个停靠的窗体中的,继承自WeifenLuo.WinFormsUI.Docking.DockContent

二、加入其它两个控件配合介面的设计:(UtilityLibrary+ IrisSkin2)

UtilityLibrary.dll为可以产生outlookbar这样的效果

IrisSkin2.dll为引入皮肤控件

三.设计完成后的介面如下:

四.其它部分就是代码部分:


.frmmain.cs部分:
private string m_strConfigFile;
        private DeserializeDockContent m_deserializeDockContent;
        public frmMain()
        {
            InitializeComponent();
            InitializeLeftBar();
        }
        private void InitializeLeftBar()
        {
            m_deserializeDockContent = new DeserializeDockContent(GetContentFromPersistString);
            frmTemp = this;
            m_strConfigFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "DockPanel.config");
            m_deserializeDockContent = new DeserializeDockContent(GetContentFromPersistString);
        }
        private IDockContent GetContentFromPersistString(string persistString)
        {
            if (persistString == typeof(frmLeftBar).ToString())
            {
                return frmLeftBar;
            }
            else
            {
                // 可以加的其它子窗体
                return null;
            }
        } .加载主窗口
private void frmMain_Load(object sender, EventArgs e)
        {
            globalcolor = System.Drawing.Color.FromArgb(Convert.ToInt32(W1.LoadXmlFileValue("config.xml", "Color", "UserColor")));
            globalcolor2 = System.Drawing.Color.FromArgb(Convert.ToInt32(W1.LoadXmlFileValue("config.xml", "Color", "IMColor")));
            CreditControl = Convert.ToBoolean(C_BaseInfo.GetsysConf().Tables[].Rows[]["CreditControl"]);
            //设置时间和日期
            tssl1.Text = "今天日期:" + DateTime.Now.ToString("yyyy-MM-dd");
            tssl2.Text = "登录时间:" + System.DateTime.Now.ToLongTimeString();
            tsslLoginUser.Text = "当前用户:" + " " + frmLogin.C_UserInfo.SysUser;
            MenuStrip ms = (MenuStrip)this.Controls["menuStrip1"];
            ArrayList arr = new ArrayList();
            dsright = C_BaseInfo.UserRight(frmLogin.C_UserInfo);
            GetMenuAllName(arr, null, , ms);//调用递归函数
            if (File.Exists(m_strConfigFile))
            {
                dockPanel1.LoadFromXml(m_strConfigFile, m_deserializeDockContent);
            }
            frmLeftBar.Show(this.dockPanel1, DockState.DockLeft);
            this.dockPanel1.BackgroundImage = global::ECM.Properties.Resources.cable_16_92;         }
.显示子窗口
private ECM.Purchase.frmPO frmpo = null;
        private void mnuPO_Click(object sender, EventArgs e)
        {
            if (FindFormName("frmPO") == null)
            {
                frmpo = new ECM.Purchase.frmPO(this);             
            frmpo.MdiParent = this;
            frmpo.Show(frmMain.frmTemp.dockPanel1);
            frmpo.Focus();
            }
            else
            {
                Form f = FindFormName("frmPO") as Form;
                f.Focus();
            }         }

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

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 != -)
                {
                    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(, );
            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(, );
            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(, );
            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(, );
            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 = ;
            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 = ;
            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

在伍华聪的博客中,看到布局控件"WeifenLuo.WinFormsUI.Docking",发现的确是一个非常棒的开源控件,用过的人都深有体会,该控件之强大、美观、不亚于商业控件。而且控件使用也是比较简单的今天在这里,我想与大家一起分这一伟大的控件。有兴趣的同学,可以一同探讨与学习一下,否则就略过吧。

一、引用方法:

1.建立一个WinForm工程,默认生成了一个WinForm窗体。

2.引用—>添加引用—>浏览—>weiFenLuo.winFormsUI.Docking.dll。

3.窗体属性IsMdiContainer:True。

4.工具箱—>右键—>选择项—>.net组件—>浏览—>weiFenLuo.winFormsUI.Docking.dll—>在工具箱出现dockPanel。

5.将dockPanel拖到窗体上,设置Dock属性,我设置的是:Fill。在这里要注意,在先增加菜单工具条,后增加dockpanel否则,会出现布局介面显示不全的问题。

以下为具体的设计介面:

左侧加入一窗体,并设计成outlookbar的样式。它其实也是在一个停靠的窗体中的,继承自WeifenLuo.WinFormsUI.Docking.DockContent

二、加入其它两个控件配合介面的设计:(UtilityLibrary+
IrisSkin2)

UtilityLibrary.dll为可以产生outlookbar这样的效果

IrisSkin2.dll为引入皮肤控件

三.设计完成后的介面如下:

四.其它部分就是代码部分:

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

WeifenLuo.WinFormsUI.Docking"的使用 z的更多相关文章

  1. 学习winform第三方界面weiFenLuo.winFormsUI.Docking.dll

    控件dockpanel中提供了几个可用的类, 重要的有两个, 一是DockPanel, 一是DockContent, DockPanel是从panel继承出来的, 用于提供可浮动的dock的子窗口进行 ...

  2. Winform中DockPanel(引用WeifenLuo.WinFormsUI.Docking.dll组件)的使用

    WeiFenLuo.WinFormsUI.Docking.dll是开源项目DockPanel Suite的一个类库,可实现像Visual Studio的窗口停靠.拖拽等功能.WeifenLuo.Win ...

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

    概述      最近几天一直在关注WinFrom方面的文章主要还是园子里伍华聪的博客,在看看我们自己写的项目差不忍赌啊,有想着提炼一下项目的公共部分,公共部分有分为 界面,类库两方面,今天主要是把界面 ...

  4. WinForm界面开发之布局控件"WeifenLuo.WinFormsUI.Docking"的使用

    WinForm界面开发之布局控件"WeifenLuo.WinFormsUI.Docking"的使用 转自:http://www.cnblogs.com/wuhuacong/arch ...

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

    概述 转自 http://www.cnblogs.com/luomingui/archive/2013/09/19/3329763.html 最近几天一直在关注WinFrom方面的文章 有想着提炼一下 ...

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

    WinForm界面布局控件WeifenLuo.WinFormsUI.Docking"的使用 (二) 编写人:CC阿爸 2015-1-29 今天我想与大家继续一起分享这一伟大的控件.有兴趣的同 ...

  7. WinFrom界面框架之WeifenLuo.WinFormsUI.Docking + OutLookBar

    本文转载:http://www.cnblogs.com/luomingui/p/3329763.html WeifenLuo.WinFormsUI.Docking + OutLookBar结合使用的效 ...

  8. 开源布局控件 WeifenLuo.WinFormsUI.Docking.dll使用

    WeifenLuo.WinFormsUI.Docking是一个很强大的界面布局控件,可以保存自定义的布局为XML文件,可以加载XML配置文件.! 先看一下效果 使用说明: 1.新建一个WinForm程 ...

  9. Winform- 界面开发之布局控件"WeifenLuo.WinFormsUI.Docking"的使用

    布局控件"WeifenLuo.WinFormsUI.Docking"是一个非常棒的开源控件,用过的人都深有体会,该控件之强大.美观.不亚于商业控件.而且控件使用也是比较简单的. 实 ...

随机推荐

  1. Log4J入门教程(二) 参数讲解

    继续接着Log4J入门教程(一)中的例子进行讲解,其中log4j.properties中的内容为    Log4j的三个重要组件—— Loggers, Appenders, Layouts ,这三个组 ...

  2. CentOS系统安装JDK

    使用yum安装 1.查看yum库是否有java安装包 yum -y list java* 2.安装jdk yum -y install  java-1.8* 3.安装完成后,执行java -versi ...

  3. android-exploitme(七):高级加密

    在上一个议题上我们解释了为什么不能把信息明文保存在设备上,应该加密,那么加密就是安全的吗? 下面来看一下, 编译BasicEncryptionSolution.apk,安装

  4. linux shell 命令学习(5) xxd- make a hexdump or do the reverse.

    对于标准输入或者给定的文件,显示其16进制的内容.也可以反过来进行转换. xxd -h[elp] xxd [options] [infile [outfile]] xxd -r[evert] [opt ...

  5. MySql存储引擎特性对比

    下表显示了各种存储引擎的特性: 其中最常见的两种存储引擎是MyISAM和InnoDB 刚接触MySQL的时候可能会有些惊讶,竟然有不支持事务的存储引擎,学过关系型数据库理论的人都知道,事务是关系型数据 ...

  6. 271. Encode and Decode Strings

    题目: Design an algorithm to encode a list of strings to a string. The encoded string is then sent ove ...

  7. 关于strlen

    strlen的实现是通过4个字节4个字节进行枚举,然后通过位运算来判断这4个字节中是否有一个字节含有0,这样的话,效率就提高了4倍. 这个效率提高是假设a&b&c&d与a&am ...

  8. !! 2.对十份论文和报告中的关于OpenCV和Android NDK开发的总结

    http://hujiaweibujidao.github.io/blog/2013/11/18/android-ndk-and-opencv-development-3/ Android Ndk a ...

  9. USACO Section 3.3: Riding the Fences

    典型的找欧拉路径的题.先贴下USACO上找欧拉路径的法子: Pick a starting node and recurse on that node. At each step: If the no ...

  10. 【Tech】Cassandra安装和启动

    1.安装 jre,配置系统环境变量: 2.安装python,配置环境变量: 3.下载cassandra,http://cassandra.apache.org/download/: 4.解压,这里我没 ...