[fix] app starting in extended screen causes an unexpected default position

This commit is contained in:
ChanginJolly 2024-05-01 16:16:28 +08:00
parent c0fd542a4a
commit 050b091ed9
2 changed files with 25 additions and 10 deletions

View File

@ -1,9 +1,11 @@
using Ink_Canvas.Helpers;
using System;
using System.Media;
using System.Runtime.InteropServices;
using System.Timers;
using System.Windows;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
namespace Ink_Canvas
@ -356,8 +358,17 @@ namespace Ink_Canvas
TbCurrentTime.Visibility = Visibility.Collapsed;
// Set to center
double screenWidth = System.Windows.SystemParameters.PrimaryScreenWidth;
double screenHeight = System.Windows.SystemParameters.PrimaryScreenHeight;
double dpiScaleX = 1, dpiScaleY = 1;
PresentationSource source = PresentationSource.FromVisual(this);
if (source != null) {
dpiScaleX = source.CompositionTarget.TransformToDevice.M11;
dpiScaleY = source.CompositionTarget.TransformToDevice.M22;
}
IntPtr windowHandle = new WindowInteropHelper(this).Handle;
System.Windows.Forms.Screen screen = System.Windows.Forms.Screen.FromHandle(windowHandle);
double screenWidth = screen.Bounds.Width / dpiScaleX, screenHeight = screen.Bounds.Height / dpiScaleY;
Left = (screenWidth / 2) - (Width / 2);
Top = (screenHeight / 2) - (Height / 2);
Left = (screenWidth / 2) - (Width / 2);
Top = (screenHeight / 2) - (Height / 2);
}

View File

@ -33,6 +33,7 @@ using Point = System.Windows.Point;
using Timer = System.Timers.Timer;
using iNKORE.UI.WPF.Modern.Helpers;
using iNKORE.UI.WPF.Helpers;
using System.Windows.Interop;
namespace Ink_Canvas {
public partial class MainWindow : Window {
@ -6488,12 +6489,6 @@ namespace Ink_Canvas {
BtnHideInkCanvas_Click(BtnHideInkCanvas, null);
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible) {
/*
if (ViewboxFloatingBar.Margin == new Thickness((SystemParameters.PrimaryScreenWidth - ViewboxFloatingBar.ActualWidth) / 2, SystemParameters.PrimaryScreenHeight - 60, -2000, -200))
{
await Task.Delay(100);
ViewboxFloatingBar.Margin = new Thickness((SystemParameters.PrimaryScreenWidth - ViewboxFloatingBar.ActualWidth) / 2, SystemParameters.PrimaryScreenHeight - 60, -2000, -200);
}*/
await Task.Delay(100);
ViewboxFloatingBarMarginAnimation(60);
}
@ -7068,8 +7063,17 @@ namespace Ink_Canvas {
}
isViewboxFloatingBarMarginAnimationRunning = true;
pos.X = (SystemParameters.PrimaryScreenWidth - ViewboxFloatingBar.ActualWidth * ViewboxFloatingBarScaleTransform.ScaleX) / 2;
pos.Y = SystemParameters.PrimaryScreenHeight - heightFromBottom * ((ViewboxFloatingBarScaleTransform.ScaleY == 1) ? 1 : 0.9);
double dpiScaleX = 1, dpiScaleY = 1;
PresentationSource source = PresentationSource.FromVisual(this);
if (source != null) {
dpiScaleX = source.CompositionTarget.TransformToDevice.M11;
dpiScaleY = source.CompositionTarget.TransformToDevice.M22;
}
IntPtr windowHandle = new WindowInteropHelper(this).Handle;
System.Windows.Forms.Screen screen = System.Windows.Forms.Screen.FromHandle(windowHandle);
double screenWidth = screen.Bounds.Width / dpiScaleX, screenHeight = screen.Bounds.Height / dpiScaleY;
pos.X = (screenWidth - ViewboxFloatingBar.ActualWidth * ViewboxFloatingBarScaleTransform.ScaleX) / 2;
pos.Y = screenHeight - heightFromBottom * ((ViewboxFloatingBarScaleTransform.ScaleY == 1) ? 1 : 0.9);
if (heightFromBottom != -60) {
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible) {