Beispiel #1
0
        // 保存form尺寸位置状态到配置文件中
        // parameters:
        //		form	Form对象
        //		strCfgTitle	配置信息路径。本函数将用此值作为SetString()或SetInt()的strPath参数使用
        public static void SaveFormStates(this ConfigSetting config,
                                          Form form,
                                          string strCfgTitle)
        {
            // 保存窗口状态
            config.Set(
                strCfgTitle, "window_state",
                Enum.GetName(typeof(FormWindowState),
                             form.WindowState));

            Size  size     = form.Size;
            Point location = form.Location;

            if (form.WindowState != FormWindowState.Normal)
            {
                size     = form.RestoreBounds.Size;
                location = form.RestoreBounds.Location;
            }

            config.SetInt(
                strCfgTitle, "width", size.Width);       // form.Width
            config.SetInt(
                strCfgTitle, "height", size.Height);     // form.Height

            config.SetInt(strCfgTitle, "x", location.X); // form.Location.X
            config.SetInt(strCfgTitle, "y", location.Y); // form.Location.Y

            // 保存MDI窗口状态 -- 是否最大化?
            if (form.ActiveMdiChild != null)
            {
                if (form.ActiveMdiChild.WindowState == FormWindowState.Minimized)
                {
                    config.Set(
                        strCfgTitle,
                        "mdi_child_window_state",
                        Enum.GetName(typeof(FormWindowState),
                                     FormWindowState.Normal));
                }
                else
                {
                    config.Set(
                        strCfgTitle,
                        "mdi_child_window_state",
                        Enum.GetName(typeof(FormWindowState),
                                     form.ActiveMdiChild.WindowState));
                }
            }
            else
            {
                config.Set(
                    strCfgTitle,
                    "mdi_child_window_state",
                    "");
            }
        }