Dockpanel 实现浮动
来源:互联网 发布:欧赔数据库下载 编辑:程序博客网 时间:2024/05/16 12:16
很多Winform的解决方案,尤其是工具类软件,需要实现浮动窗体,以及多标签窗体的整体界面架构,类似VS 2005。如果是基于.NET 的实现,大名鼎鼎的Dockpanel是不二之选。作者最近的两个工具类软件项目用到了Dockpanel,在此记录一下Dockpanel框架的搭建过 程,和使用过程中的注意点。
首先,下载Dockpanel suite,在sf上能下到最新的2.3.1版本的dll,和demo.
http://sourceforge.net/projects/dockpanelsuite/
下面介绍一下dockpanel suite的使用过程:
1,在主窗体中添加dockpanel控件,并把设置主窗体 IsMdiContainer=true。不然在向主窗体中添加标签窗体时,会报异常:Invalid parent form. When using DockingMdi or SystemMdi document style, the DockPanel control must be the child control of the main MDI container form.
并把设置dockpanel 的documentstyle :dockPanel.DocumentStyle = DocumentStyle.DockingMdi.(注:documentstyle 有四种,要实现浮动和多标签效果可以使用:DockingMdi 或DockingSdi,在下面的demo中可以测试,没有看出二者的区别,还望高手指教)
2,加载Dockpanel 的配置文件。Dockpanel suite 是基于配置文件的,其配置文件Dockpanel.config可以放置到指定的位置。在主窗体的load 事件中要做加载配置文件的工作。需要执行配置文件的路径,并使用dockpanel 的LoadFromXml方法加载需要显示的浮动窗体,在initDockpanel 中自定义装载的哪些浮动窗体。
1 private void frmMain_Load(object sender, EventArgs e)2 {3 this.dockPanel.DocumentStyle = DocumentStyle.DockingMdi;4 this.m_DockPath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "DockPanel.config");5 this.InitDockPanel();6 }7 8 /// <summary>9 /// 按照配置文件初始化Dockpanel10 /// </summary>11 private void InitDockPanel()12 {13 try14 {15 //根据配置文件动态加载浮动窗体16 this.dockPanel.LoadFromXml(this.m_DockPath, delegate(string persistString)17 {18 if (persistString == typeof(FrmSolution).ToString())19 {20 return FrmSolution.GetInstance();21 }22 if (persistString == typeof(frmProperty).ToString())23 {24 return frmProperty.GetInstance();25 }26 if (persistString == typeof(FrmToolBox).ToString())27 {28 return FrmToolBox.GetInstance();29 }30 if (persistString == typeof(FrmOutput).ToString())31 {32 return FrmOutput.GetInstance();33 }34 return null;35 });36 }37 catch (Exception)38 {39 //配置文件不存在或配置文件有问题时 按系统默认规则加载子窗体40 FrmSolution.GetInstance().Show(this.dockPanel, AppConfig.ms_FrmSolutionState);41 frmProperty.GetInstance().Show(this.dockPanel, AppConfig.ms_FrmProState);42 FrmToolBox.GetInstance().Show(this.dockPanel, AppConfig.ms_FrmToolBoxState);43 FrmOutput.GetInstance().Show(this.dockPanel, AppConfig.ms_FrmOutPutState);44 }45 }注:在此加入的特殊处理,来改进Dockpanel 的加载,如果dockpanel.config不存在(不小心删除了),可以按照Appconfig中预定义的dockstate显示。
3,浮动窗体和多标签窗体
浮动窗体和标签窗体需要继承自DockContent,为了保证在关闭某一浮动窗体之后,再打开时能够在原位置显示,要对浮动窗体处理,处理窗体的DockstateChanged事件。代码如下
1 /// <summary>2 /// 标签窗体dock位置改变,记录到公共类3 /// </summary>4 /// <param name="sender"></param>5 /// <param name="e"></param>6 private void frmServer_DockStateChanged(object sender, EventArgs e)7 {8 //关闭时(dockstate为unknown) 不把dockstate保存9 if (Instance != null)10 {11 if (this.DockState == DockState.Unknown || this.DockState == DockState.Hidden)12 {13 return;14 }15 AppConfig.ms_FrmSolutionState = this.DockState;16 }17 }注意:两种dockstate:unknown ,hidden 不能记录,这两种状态加载时会出现异常。
浮动窗体使用:frmServer.Show(this.dockPanel, dockstate);
标签窗体使用:dummyDoc.Show(dockPanel);
4,保存浮动窗体和标签窗体的状态
如果下次打开程序时,浮动窗体的显示位置和关闭时一致。可以在主窗体的frmMain_FormClosing事件中调用:
dockPanel.SaveAsXml(this.m_DockPath)
以上4点是搭建基于dockpanel 浮动和多标签窗体系统 的主要步骤。
- Dockpanel 实现浮动
- 利用DockPanel实现可停靠、可浮动、多文档窗体
- Dockpanel 实现浮动和多标签窗体解决方案
- 利用DockPanel实现可停靠、可浮动、多文档窗体
- Dockpanel 实现浮动和多标签窗体解决方案(转)
- C#实现浮动和多标签窗体解决方案---使用Dockpanel
- DockPanel
- dockPanel
- dockpanel
- DockPanel
- DockPanel
- DockPanel
- DockPanel
- WinForm:DockPanel实现窗体的停靠
- 利用DockPanel与C#制作窗体浮动和停靠(vs2010)
- 利用DockPanel与C#制作窗体浮动和停靠(vs2010)
- 实现仿Visual Studio风格的控件DockPanel
- 实现浮动按钮
- windows错误码查询
- 使程序更健壮 对NString 为 nil null 的判断
- WinForm界面开发之“OutLookBar”工具条
- Wireshark 教學
- S3C2416之3G s3c2416从NAND FLASH启动
- Dockpanel 实现浮动
- 巧用windows cmd 查询网络问题
- 嵌入式3G上网
- android自制的软件如何添加到打开方式
- 关于struts和Tomcat7报告:Memory Leak 的问题。
- android:android.intent.action大全
- JAVA生成Word文档(经过测试)
- 当Office PIA遭遇C# 4.0
- ЗАО\ООО\ОАО