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


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

    ()

    编写人:CC阿爸

     

    2015-1-28

     

    伍华聪的博客中,看到布局控件"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为引入皮肤控件

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

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

    1.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;
                }
            }

    2.加载主窗口
    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[0].Rows[0]["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, null0, 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;




            }
    3.显示子窗口
    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();
                }

            }

     

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

    http://www.cnblogs.com/wuhuacong/archive/2009/07/09/1520082.html

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

    欢迎加入技术分享群!!!!

  • 相关阅读:
    贝云cms内容管理系统(thinkphp5.0开源cms管理系统)
    NGINX.conf配置文件支持pathinfo
    阿里云视频直播PHPSDK接入教程
    如何在Nginx下配置PHP程序环境
    tomcat 内存参数优化示例
    12组免费的CSS3按钮强力推荐 狼人:
    9款jQuery插件为你的网站增加亮点 狼人:
    TUP第11期:腾讯、豆瓣精英实例诠释互联网研发之道 狼人:
    【TUP第11期】腾讯黄朝兴:浅谈客户端架构 狼人:
    Linus Torvalds:回顾Linux20年 狼人:
  • 原文地址:https://www.cnblogs.com/bribe/p/4254926.html
Copyright © 2020-2023  润新知