Fix window restore maximize statate on secondary monitor.

This commit is contained in:
MBucari 2023-03-11 21:33:55 -07:00
parent 5ec01913d5
commit 3f0e6b9ee5

View File

@ -2,6 +2,7 @@
using System.Linq; using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using LibationFileManager; using LibationFileManager;
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
namespace LibationWinForms namespace LibationWinForms
{ {
@ -44,6 +45,17 @@ namespace LibationWinForms
var rect = new Rectangle(x, y, savedState.Width, savedState.Height); var rect = new Rectangle(x, y, savedState.Width, savedState.Height);
if (savedState.IsMaximized)
{
//When a window is maximized, the client rectangle is not on a screen (y is negative).
form.StartPosition = FormStartPosition.Manual;
form.DesktopBounds = rect;
// FINAL: for Maximized: start normal state, set size and location, THEN set max state
form.WindowState = FormWindowState.Maximized;
}
else
{
// is proposed rect on a screen? // is proposed rect on a screen?
if (Screen.AllScreens.Any(screen => screen.WorkingArea.Contains(rect))) if (Screen.AllScreens.Any(screen => screen.WorkingArea.Contains(rect)))
{ {
@ -56,8 +68,8 @@ namespace LibationWinForms
form.Size = rect.Size; form.Size = rect.Size;
} }
// FINAL: for Maximized: start normal state, set size and location, THEN set max state form.WindowState = FormWindowState.Normal;
form.WindowState = savedState.IsMaximized ? FormWindowState.Maximized : FormWindowState.Normal; }
} }
public static void SaveSizeAndLocation(this Form form, Configuration config) public static void SaveSizeAndLocation(this Form form, Configuration config)