////////////////////////////////////////////////////////////////////////// protected void LoadLayout(SettingsNode RootNode) { SettingsNode LayoutNode = RootNode.GetNode("Layout\\" + this.Name); if (LayoutNode != null) { // load position Point FormLoc = new Point(LayoutNode.GetInt("FormPosX", this.Location.X), LayoutNode.GetInt("FormPosY", this.Location.Y)); // load size if (this.FormBorderStyle == FormBorderStyle.Sizable || this.FormBorderStyle == FormBorderStyle.SizableToolWindow) { this.Size = new Size(LayoutNode.GetInt("FormWidth", this.Size.Width), LayoutNode.GetInt("FormHeight", this.Size.Height)); } // make sure the position/size is valid on current monitor setup bool FoundScreen = false; Point LowerRight = new Point(FormLoc.X + this.Size.Width, FormLoc.Y + this.Size.Height); foreach (Screen Scr in Screen.AllScreens) { if (Scr.Bounds.Contains(FormLoc) || Scr.Bounds.Contains(LowerRight)) { FoundScreen = true; } } if (FoundScreen) { this.Location = FormLoc; } // remember window position FormStateRect.Location = this.Location; FormStateRect.Size = this.Size; this.WindowState = (FormWindowState)LayoutNode.GetInt("FormState", (int)FormWindowState.Normal); LoadControls(this, LayoutNode); } else { FormStateRect.Location = this.Location; FormStateRect.Size = this.Size; } }
////////////////////////////////////////////////////////////////////////// public int GetInt(string Path, int InitValue) { SettingsNode Node = GetNode(Path, false, false); if (Node != null) { return(Node.GetInt()); } else { return(InitValue); } }
////////////////////////////////////////////////////////////////////////// protected void LoadControls(Control ParentControl, SettingsNode RootNode) { foreach (Control C in ParentControl.Controls) { if (C is ILayoutAwareControl) { ((ILayoutAwareControl)C).LoadControlLayout(RootNode); } else { if (C is SplitContainer) { SplitContainer Ctrl = C as SplitContainer; if (!Ctrl.IsSplitterFixed) { SettingsNode Node = RootNode.GetNode(Ctrl.Name); if (Node != null) { try { Ctrl.SplitterDistance = Node.GetInt("SplitterDistance", Ctrl.SplitterDistance); } catch { } } } } if (C is ListView) { ListView Ctrl = C as ListView; SettingsNode Node = RootNode.GetNode(Ctrl.Name, false, true); if (Node != null) { for (int i = 0; i < Ctrl.Columns.Count; i++) { ColumnHeader Col = Ctrl.Columns[i]; Col.Width = Node.GetInt("Col" + i.ToString() + "Width", Col.Width); } } } if (C is TabControl) { TabControl Ctrl = C as TabControl; SettingsNode Node = RootNode.GetNode(Ctrl.Name, false, true); if (Node != null) { int SelIndex = Node.GetInt("SelectedIndex", Ctrl.SelectedIndex); if (SelIndex >= 0 && SelIndex < Ctrl.TabCount) { Ctrl.SelectedIndex = SelIndex; } } } } if (C.Controls.Count > 0) { LoadControls(C, RootNode); } } }