/// ------------------------------------------------------------------------------------ /// <summary> /// Assigns window properties to a form from an XmlDocument. /// </summary> /// <param name="frm">Form to load settings into</param> /// <param name="setLocationOnly">true if the method should only set the form's /// location and not its size. Otherwise, false.</param> /// <param name="centerByDefault">true if the form should be centered in the /// screen when there are no saved properties for it.</param> /// <returns>True on success</returns> /// ------------------------------------------------------------------------------------ public bool LoadFormProperties(Form frm, bool setLocationOnly, bool centerByDefault) { if (m_xmlDoc == null || frm == null) { return(false); } if (centerByDefault) { Utils.CenterFormInScreen(frm); } XmlNode node = FindChildNode(kWindowStatesNode, frm.Name); if (node == null) { return(false); } string sdpi = XmlHelper.GetAttributeValue(node, "dpi"); float dpi; if (!float.TryParse(sdpi, out dpi)) { dpi = 0; } // Only set the form's size and location if the dpi setting now is // the same as it was the last time the form's settings were saved. if (dpi == m_currSystemDpi) { if (!setLocationOnly) { frm.Height = XmlHelper.GetIntFromAttribute(node, "height", frm.Height); frm.Width = XmlHelper.GetIntFromAttribute(node, "width", frm.Width); } frm.Top = XmlHelper.GetIntFromAttribute(node, "top", frm.Top); frm.Left = XmlHelper.GetIntFromAttribute(node, "left", frm.Left); } if (!setLocationOnly) { frm.WindowState = (XmlHelper.GetAttributeValue(node, "state") == "Maximized" ? FormWindowState.Maximized : frm.WindowState = FormWindowState.Normal); } return(true); }
/// ------------------------------------------------------------------------------------ protected override void OnShown(EventArgs e) { base.OnShown(e); Utils.CenterFormInScreen(this); }