Exemplo n.º 1
0
 /// <summary>Загрузить параметры отображения из файла и присвоить форме
 /// </summary>
 public static void LoadFromFile(Form form, string fileName = "", FormOptionsSetType setType = FormOptionsSetType.All)
 {
     if (form == null)
     {
         return;
     }
     FormsConfig.CreateFromFile(fileName)?.SetToForm(form, setType);
 }
Exemplo n.º 2
0
 /// <summary>Загрузить параметры отображения из XML и присвоить форме
 /// </summary>
 public static void LoadFromXML(Form form, string xml, FormOptionsSetType setType = FormOptionsSetType.All)
 {
     if (form == null)
     {
         return;
     }
     FormsConfig.CreateFromXML(xml)?.SetToForm(form, setType);
 }
Exemplo n.º 3
0
 /// <summary>Загрузить параметры отображения формы</summary>
 public void LoadFormOptions(Form form, FormOptionsSetType setType = FormOptionsSetType.All)
 {
     if (AppConfig.HasProp("UserOptionsInDB"))
     {
         FormOptions.LoadFromXML(form, userFormOptions, setType);
     }
     if (AppConfig.HasProp("UserOptionsInFile"))
     {
         FormOptions.LoadFromFile(form, null, setType);
     }
 }
Exemplo n.º 4
0
        // установить параметры для формы
        internal void SetToForm(Form form, FormOptionsSetType setType = FormOptionsSetType.All)
        {
            string      mode = form.StartPosition == FormStartPosition.CenterParent ? "Parent" : "Default";
            FormOptions opt  = Forms.FirstOrDefault(x => x.Name == form.Name && x.Mode == mode);

            if (opt == null)
            {
                return;
            }

            if (setType == FormOptionsSetType.All || setType == FormOptionsSetType.Size)
            {
                if (opt.Width >= form.MinimumSize.Width)
                {
                    form.Width = opt.Width;
                }
                //else
                //    form.Width = form.MinimumSize.Width > 0 ? form.MinimumSize.Width : 100;
                if (opt.Height >= form.MinimumSize.Height)
                {
                    form.Height = opt.Height;
                }
                //else
                //    form.Height = form.MinimumSize.Height > 0 ? form.MinimumSize.Height : 100;
                if (AppConfig.HasProp("RestoreFormPos"))
                {
                    form.Top  = opt.Top;
                    form.Left = opt.Left;
                }
            }

            if (setType == FormOptionsSetType.All)
            {
                foreach (var item in opt.Splits)
                {
                    Control c = form.GetControl(item.Name);
                    if (c is SplitContainer && item.Distance > 0)
                    {
                        var sc = (SplitContainer)c;
                        if ((sc.Orientation == Orientation.Horizontal && item.Distance < form.Height) ||
                            (sc.Orientation == Orientation.Vertical && item.Distance < form.Width))
                        {
                            sc.SplitterDistance = item.Distance;
                        }
                        sc.Panel1Collapsed = item.Panel1Collapsed;
                        sc.Panel2Collapsed = item.Panel2Collapsed;
                    }
                }
            }

            if (setType == FormOptionsSetType.All || setType == FormOptionsSetType.Grid)
            {
                foreach (var item in opt.Grids)
                {
                    Control c = form.GetControl(item.Name);
                    if (c is DataGridView)
                    {
                        DataGridView g = ((DataGridView)c);
                        foreach (DataGridViewColumn col in g.Columns)
                        {
                            ColumnOptions copt = item.Columns.FirstOrDefault(x => x.Name == col.Name);
                            if (copt != null)
                            {
                                col.Width = copt.Width;
                                if (copt.Pos >= 0 && copt.Pos < g.Columns.Count)
                                {
                                    col.DisplayIndex = copt.Pos;
                                }
                                else
                                {
                                    col.DisplayIndex = g.Columns.Count - 1;
                                }
                                col.Visible = copt.Visible;
                            }
                        }
                        var colCheck = g.Columns[GridOptions.checkColumnName];
                        if (colCheck != null)
                        {
                            colCheck.DisplayIndex = 0;
                        }
                    }
                }
            }

            if (setType == FormOptionsSetType.All && form is IDataForm)
            {
                ((IDataForm)form).SetUiParamsProperties(opt.ControlValues);
            }
        }