Fix window restore maximize statate on secondary monitor.
This commit is contained in:
parent
5ec01913d5
commit
3f0e6b9ee5
@ -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,20 +45,31 @@ namespace LibationWinForms
|
|||||||
|
|
||||||
var rect = new Rectangle(x, y, savedState.Width, savedState.Height);
|
var rect = new Rectangle(x, y, savedState.Width, savedState.Height);
|
||||||
|
|
||||||
// is proposed rect on a screen?
|
if (savedState.IsMaximized)
|
||||||
if (Screen.AllScreens.Any(screen => screen.WorkingArea.Contains(rect)))
|
|
||||||
{
|
{
|
||||||
|
//When a window is maximized, the client rectangle is not on a screen (y is negative).
|
||||||
form.StartPosition = FormStartPosition.Manual;
|
form.StartPosition = FormStartPosition.Manual;
|
||||||
form.DesktopBounds = rect;
|
form.DesktopBounds = rect;
|
||||||
|
|
||||||
|
// FINAL: for Maximized: start normal state, set size and location, THEN set max state
|
||||||
|
form.WindowState = FormWindowState.Maximized;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
form.StartPosition = FormStartPosition.WindowsDefaultLocation;
|
// is proposed rect on a screen?
|
||||||
form.Size = rect.Size;
|
if (Screen.AllScreens.Any(screen => screen.WorkingArea.Contains(rect)))
|
||||||
}
|
{
|
||||||
|
form.StartPosition = FormStartPosition.Manual;
|
||||||
|
form.DesktopBounds = rect;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
form.StartPosition = FormStartPosition.WindowsDefaultLocation;
|
||||||
|
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)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user