private void RestoreWindowState() { WindowState = FormWindowState.Normal; StartPosition = FormStartPosition.WindowsDefaultBounds; XMLProfileSettings xml = new XMLProfileSettings(); var name = $"OpenGLPreview_{InstanceId}"; _showStatus = xml.GetSetting(XMLProfileSettings.SettingType.AppSettings, string.Format("{0}/ShowStatus", name), true); _alwaysOnTop = xml.GetSetting(XMLProfileSettings.SettingType.AppSettings, string.Format("{0}/AlwaysOnTop", name), false); _enableLightScaling = xml.GetSetting(XMLProfileSettings.SettingType.AppSettings, string.Format("{0}/EnableLightScaling", name), true); ConfigureStatusBar(); ConfigureAlwaysOnTop(); var desktopBounds = new Rectangle( new Point( xml.GetSetting(XMLProfileSettings.SettingType.AppSettings, string.Format("{0}/WindowLocationX", name), Location.X), xml.GetSetting(XMLProfileSettings.SettingType.AppSettings, string.Format("{0}/WindowLocationY", name), Location.Y)), new Size(100, 100)); if (IsVisibleOnAnyScreen(desktopBounds)) { StartPosition = FormStartPosition.Manual; DesktopLocation = desktopBounds.Location; //if ( // xml.GetSetting(XMLProfileSettings.SettingType.AppSettings, string.Format("{0}/WindowState", Name), "Normal") // .Equals("Maximized")) //{ // WindowState = FormWindowState.Maximized; //} } else { // this resets the upper left corner of the window to windows standards StartPosition = FormStartPosition.WindowsDefaultLocation; } var cHeight = xml.GetSetting(XMLProfileSettings.SettingType.AppSettings, string.Format("{0}/ClientHeight", name), _background.HasBackground ? _background.Height : 0); var cWidth = xml.GetSetting(XMLProfileSettings.SettingType.AppSettings, string.Format("{0}/ClientWidth", name), _background.HasBackground ? _background.Width : 0); if (cHeight == 0 && cWidth == 0) { var size = FindMaxPreviewSize(); if (size.Height > 50 && size.Width > 50) { cHeight = size.Height; cWidth = size.Width; } else { cHeight = _height; cWidth = _width; } } ClientSize = new Size(cWidth, cHeight); _width = cWidth; _height = cHeight; }
private void RestoreWindowState() { WindowState = FormWindowState.Normal; StartPosition = FormStartPosition.WindowsDefaultBounds; XMLProfileSettings xml = new XMLProfileSettings(); var name = $"Preview_{InstanceId}"; _showStatus = xml.GetSetting(XMLProfileSettings.SettingType.AppSettings, string.Format("{0}/ShowStatus", name), true); _showBorders = xml.GetSetting(XMLProfileSettings.SettingType.AppSettings, string.Format("{0}/ShowBorders", name), true); _alwaysOnTop = xml.GetSetting(XMLProfileSettings.SettingType.AppSettings, string.Format("{0}/AlwaysOnTop", name), false); _lockPosition = xml.GetSetting(XMLProfileSettings.SettingType.AppSettings, string.Format("{0}/LockPosition", name), false); ZoomLevel = xml.GetSetting(XMLProfileSettings.SettingType.AppSettings, string.Format("{0}/ZoomLevel", name), 1d); ConfigureStatusBar(); ConfigureBorders(); ConfigureAlwaysOnTop(); var desktopBounds = new Rectangle( new Point( xml.GetSetting(XMLProfileSettings.SettingType.AppSettings, string.Format("{0}/WindowLocationX", name), Location.X), xml.GetSetting(XMLProfileSettings.SettingType.AppSettings, string.Format("{0}/WindowLocationY", name), Location.Y)), new Size( xml.GetSetting(XMLProfileSettings.SettingType.AppSettings, string.Format("{0}/WindowWidth", name), 0), xml.GetSetting(XMLProfileSettings.SettingType.AppSettings, string.Format("{0}/WindowHeight", name), 0))); if (desktopBounds.Width < 20) { if (gdiControl.Background != null && gdiControl.Background.Width > 20) { desktopBounds.Width = gdiControl.Background.Width + Width - ClientSize.Width; } else { desktopBounds.Width = 400; } } if (desktopBounds.Height < 10) { if (gdiControl.Background != null && gdiControl.Background.Height > 10) { desktopBounds.Height = gdiControl.Background.Height + Height - ClientSize.Height + (statusStrip.Visible?statusStrip.Height:0); } else { desktopBounds.Height = 300; } } var windowState = xml.GetSetting(XMLProfileSettings.SettingType.AppSettings, string.Format("{0}/WindowState", name), "Normal"); if (windowState.Equals("Maximized") && IsVisibleOnAnyScreen(desktopBounds)) { StartPosition = FormStartPosition.Manual; DesktopLocation = desktopBounds.Location; WindowState = FormWindowState.Maximized; } else if (AreCornersVisibleOnAnyScreen(desktopBounds)) { StartPosition = FormStartPosition.Manual; DesktopBounds = desktopBounds; } else { // this resets the upper left corner of the window to windows standards StartPosition = FormStartPosition.WindowsDefaultLocation; // we can still apply the saved size Size = new Size(desktopBounds.Width, desktopBounds.Height); } }
private void Form_ColorLibrary_FormClosing(object sender, FormClosingEventArgs e) { var xml = new XMLProfileSettings(); xml.PutSetting(XMLProfileSettings.SettingType.AppSettings, string.Format("{0}/ColorLibraryScale", Name), _colorLibraryScale.ToString(CultureInfo.InvariantCulture)); }