diff --git a/NAPS2.Lib.WinForms/EtoForms/WinForms/WinFormsEtoPlatform.cs b/NAPS2.Lib.WinForms/EtoForms/WinForms/WinFormsEtoPlatform.cs index 5420ecec3f..1969a16d9e 100644 --- a/NAPS2.Lib.WinForms/EtoForms/WinForms/WinFormsEtoPlatform.cs +++ b/NAPS2.Lib.WinForms/EtoForms/WinForms/WinFormsEtoPlatform.cs @@ -277,7 +277,13 @@ public override void InitForm(Window window) form.DpiChanged += (_, _) => (window as IFormBase)?.LayoutController.Invalidate(); } - public override float GetScaleFactor(Window window) => window.ToNative().DeviceDpi / 96f; + public override float GetScaleFactor(Window window) + { + var form = window.ToNative(); + // Force creation of form handle + _ = form.Handle; + return form.DeviceDpi / 96f; + } public override bool ScaleLayout => true; diff --git a/NAPS2.Lib/EtoForms/FormStateController.cs b/NAPS2.Lib/EtoForms/FormStateController.cs index 96667cc7b0..5149eab673 100644 --- a/NAPS2.Lib/EtoForms/FormStateController.cs +++ b/NAPS2.Lib/EtoForms/FormStateController.cs @@ -49,7 +49,7 @@ public void UpdateLayoutSize(LayoutController layoutController) var oldDefaultClientSize = DefaultClientSize; var oldMaximumClientSize = _maximumClientSize; DefaultClientSize = layoutController.GetLayoutSize(true) + DefaultExtraLayoutSize; - _maximumClientSize = FixedHeightLayout ? new Size(0, _minimumClientSize.Height) : Size.Empty; + _maximumClientSize = FixedHeightLayout || !Resizable ? new Size(0, _minimumClientSize.Height) : Size.Empty; if (_loaded) { @@ -111,10 +111,6 @@ protected void DoRestoreFormState() throw new InvalidOperationException(); } var location = new Point(_formState.Location.X, _formState.Location.Y); - var scale = EtoPlatform.Current.GetLayoutScaleFactor(_window); - var size = new Size( - (int) Math.Round(_formState.Size.Width * scale), - (int) Math.Round(_formState.Size.Height * scale)); if (!location.IsZero) { if (Screen.Screens.Any(x => x.WorkingArea.Contains(location))) @@ -124,6 +120,10 @@ protected void DoRestoreFormState() EtoPlatform.Current.SetFormLocation(_window, location); } } + var scale = EtoPlatform.Current.GetLayoutScaleFactor(_window); + var size = new Size( + (int) Math.Round(_formState.Size.Width * scale), + (int) Math.Round(_formState.Size.Height * scale)); if (!size.IsEmpty && Resizable) { if (!_minimumClientSize.IsEmpty)