diff --git a/source/CPDLCPlugin/Windows/WindowManager.cs b/source/CPDLCPlugin/Windows/WindowManager.cs index 2a8bd7b..dc232d6 100644 --- a/source/CPDLCPlugin/Windows/WindowManager.cs +++ b/source/CPDLCPlugin/Windows/WindowManager.cs @@ -6,6 +6,7 @@ namespace CPDLCPlugin.Windows; public class WindowManager(IGuiInvoker guiInvoker) { readonly IDictionary _forms = new Dictionary(); + readonly IDictionary _lastLocations = new Dictionary(); readonly object _gate = new(); public void FocusOrCreateWindow( @@ -33,9 +34,23 @@ public void FocusOrCreateWindow( StartPosition = FormStartPosition.CenterParent }; + if (_lastLocations.TryGetValue(key, out var lastLocation)) + { + form.StartPosition = FormStartPosition.Manual; + form.Location = lastLocation; + } + configureForm?.Invoke(form); - form.Closed += (_, _) => TryRemoveWindowInternal(key); + form.Closed += (_, _) => + { + // If the window is minimised or maximised, Location is not the normal position of the window + _lastLocations[key] = form.WindowState == FormWindowState.Normal + ? form.Location + : form.RestoreBounds.Location; + + TryRemoveWindowInternal(key); + }; form.Show(mainForm); _forms[key] = form;