zoukankan      html  css  js  c++  java
  • 界面布局控件WeifenLuo.WinFormsUI.Docking_保存窗体布局

    界面布局控件-WeifenLuo.WinFormsUI.Docking_保存窗体布局

    //201117

    我们在使用WeifenLuo.WinFormsUI.Docking控件控制窗体布局后,可以将当前的控件布局格保存下来,当系统再次重新启动的时候,就显示原来已经保存的页面布局格式。

    实现思路:

    1) 系统退出前,将当前的页面布局保存下来,以XML文件存放

    2) 系统加载后,读取该XML的配置信息,然后根据读取的配置信息,显示页面格局。

    实现效果如下所示:

    保存前的布局样式,也是系统第一运行后的现实效果

    调整后的系统布局

    实现步骤:

    1) 系统退出前,保存当前的布局,代码如下所示:

    private void Form1_FormClosing(object sender, FormClosingEventArgs e)

            {

                string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath),"DockPanel.config");

    //configFile 配置文件保存的路径

                dockPanel1.SaveAsXml(configFile);

            }

    2)窗体加载前的代码

         child_1 b = new child_1();//第一个子窗体

            child_2 c = new child_2();//第二个子窗体

            private DeserializeDockContent ddc;//全局变量

            //辅助函数,这里需要注意的是,有几个字控件,就需要有几个if()语句来判断

            private IDockContent GetContentFromPersistString(string persistString)

            {

                //persistString=命名空间+窗体类的命名,比如:WindowsFormsApplication1+child_1

                if (persistString == typeof(child_1).ToString())

                {

                    return b;

                }

                if (persistString == typeof(child_2).ToString())

                {

     

                    return c;

                }

                return null;

     

            }

    //窗体加载调用的函数

      private void Form1_Load(object sender, EventArgs e)

            {

                ddc = new DeserializeDockContent(GetContentFromPersistString); // 放在后面的话会出错。

                //返回配置文件的路径

                string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "DockPanel.config");

                if (File.Exists(configFile))

                {

    //如果配置文件存在,就调用该函数,读取配置文件信息

                    dockPanel1.LoadFromXml(configFile, ddc);

                }

                else

                {

    //如果第一次运行系统,或者不存在配置文件,运行下面的代码,显示最原始状态的控件显示布局

                    b.Show(this.dockPanel1);

                    b.DockTo(this.dockPanel1, DockStyle.Left);

                    c.Show(this.dockPanel1);

                    c.DockTo(this.dockPanel1, DockStyle.Right);

                }

            }

  • 相关阅读:
    今天遇到的报错Babel noteThe code generator has deoptimised the styling of ...as it exceeds the max of 500KB.
    轻松理解Promise.all 、Promise.then、Promise.race有什么区别以及使用方法
    JS循环类数组对象,获得页面所有的某个ClssaName,处理它的属性
    Angular在用户登录后设置授权请求头headers.append('Authorization', 'token');
    webpack配置less以及js中引入的图片问题
    超级容易理解的Three.js中的物体rotation
    新下载了一个框架,然后npm install时候报错npm ERR! Maximum call stack size exceeded
    webpack打包后发现有一部分代码还携带注释,如何解决?/webpack打包删除注释以及console.log--快快点进来看一看吧~~
    composer 下载扩展包
    postman 模拟登录状态
  • 原文地址:https://www.cnblogs.com/xingchen/p/1930276.html
Copyright © 2011-2022 走看看