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。
![](http://s1.VeVb.com/20150728/280906418005054.jpg)
5.将dockPanel拖到窗体上,设置Dock属性,我设置的是:Fill。在这里要注意,在先增加菜单工具条,后增加dockpanel否则,会出现布局介面显示不全的问题。
![](http://s1.VeVb.com/20150728/280907027848899.jpg)
以下为具体的设计介面:
![](http://s1.VeVb.com/20150728/280907453161758.jpg)
左侧加入一窗体,并设计成Outlookbar的样式。它其实也是在一个停靠的窗体中的,继承自WeifenLuo.WinFormsUI.Docking.DockContent
![](http://s1.VeVb.com/20150728/280908177224326.jpg)
二、加入其它两个控件配合介面的设计: (UtilityLibrary+IrisSkin2)
UtilityLibrary.dll为可以产生outlookbar这样的效果
IrisSkin2.dll为引入皮肤控件
三.设计完成后的介面如下:
![](http://s1.VeVb.com/20150728/280908576593428.jpg)
四.其它部分就是代码部分:
1.frmmain.cs部分:PRivatestringm_strConfigFile;privateDeserializeDockContentm_deserializeDockContent;publicfrmMain(){InitializeComponent();InitializeLeftBar();}privatevoidInitializeLeftBar(){m_deserializeDockContent=newDeserializeDockContent(GetContentFromPersistString);frmTemp=this;m_strConfigFile=Path.Combine(Path.GetDirectoryName(application.ExecutablePath),"DockPanel.config");m_deserializeDockContent=newDeserializeDockContent(GetContentFromPersistString);}privateIDockContentGetContentFromPersistString(stringpersistString){if(persistString==typeof(frmLeftBar).ToString()){returnfrmLeftBar;}else{//可以加的其它子窗体returnnull;}}2.加载主窗口privatevoidfrmMain_Load(objectsender,EventArgse){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;MenuStripms=(MenuStrip)this.Controls["menuStrip1"];ArrayListarr=newArrayList();dsright=C_BaseInfo.UserRight(frmLogin.C_UserInfo);GetMenuAllName(arr,null,0,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.显示子窗口privateECM.Purchase.frmPOfrmpo=null;privatevoidmnuPO_Click(objectsender,EventArgse){if(FindFormName("frmPO")==null){frmpo=newECM.Purchase.frmPO(this);frmpo.MdiParent=this;frmpo.Show(frmMain.frmTemp.dockPanel1);frmpo.Focus();}else{Formf=FindFormName("frmPO")asForm;f.Focus();}}![](http://s1.VeVb.com/20150728/280910518941126.jpg)
以下为其它同学编写有关该控件的技术文档,供大家参考
http://www.VEVb.com/wuhuacong/archive/2009/07/09/1520082.html
http://www.VEVb.com/luomingui/archive/2013/09/19/3329763.html
欢迎加入技术分享群!!!!