From e972adfbcb1774b04a748031cef0f65c32429857 Mon Sep 17 00:00:00 2001
From: CJKmkp <2564608840@qq.com>
Date: Sat, 27 Dec 2025 22:57:22 +0800
Subject: [PATCH] fix:issue #332
---
Ink Canvas/MainWindow.xaml.cs | 70 +++++++++++++++++++
.../MainWindow_cs/MW_FloatingBarIcons.cs | 4 ++
Ink Canvas/Windows/TimerControl.xaml | 6 +-
Ink Canvas/Windows/TimerControl.xaml.cs | 48 +++++++++++++
4 files changed, 127 insertions(+), 1 deletion(-)
diff --git a/Ink Canvas/MainWindow.xaml.cs b/Ink Canvas/MainWindow.xaml.cs
index 8f62e33c..ede1c388 100644
--- a/Ink Canvas/MainWindow.xaml.cs
+++ b/Ink Canvas/MainWindow.xaml.cs
@@ -340,6 +340,66 @@ namespace Ink_Canvas
}
}
+ ///
+ /// 根据DPI缩放因子调整TimerContainer的尺寸
+ ///
+ private void AdjustTimerContainerSize()
+ {
+ try
+ {
+ var timerContainer = FindName("TimerContainer") as FrameworkElement;
+ if (timerContainer == null) return;
+
+ var source = System.Windows.PresentationSource.FromVisual(this);
+ if (source != null)
+ {
+ var dpiScaleX = source.CompositionTarget.TransformToDevice.M11;
+ var dpiScaleY = source.CompositionTarget.TransformToDevice.M22;
+
+ // 如果DPI缩放因子大于1.25,则适当缩小容器尺寸
+ // 这样可以确保在高DPI屏幕上,计时器窗口的物理像素大小不会过大
+ if (dpiScaleX > 1.25 || dpiScaleY > 1.25)
+ {
+ // 使用较小的缩放因子来限制最大尺寸
+ double scaleFactor = Math.Min(dpiScaleX, dpiScaleY);
+
+ // 计算目标物理像素大小(约1350x750物理像素)
+ // 然后转换为逻辑像素
+ double targetPhysicalWidth = 1350;
+ double targetPhysicalHeight = 750;
+
+ // 转换为逻辑像素
+ double maxWidth = targetPhysicalWidth / scaleFactor;
+ double maxHeight = targetPhysicalHeight / scaleFactor;
+
+ // 确保不会小于原始尺寸的70%
+ maxWidth = Math.Max(maxWidth, 900 * 0.7);
+ maxHeight = Math.Max(maxHeight, 500 * 0.7);
+
+ // 应用调整后的尺寸
+ timerContainer.Width = maxWidth;
+ timerContainer.Height = maxHeight;
+ }
+ else
+ {
+ // 标准DPI,使用原始尺寸
+ timerContainer.Width = 900;
+ timerContainer.Height = 500;
+ }
+ }
+ else
+ {
+ // 无法获取DPI信息,使用原始尺寸
+ timerContainer.Width = 900;
+ timerContainer.Height = 500;
+ }
+ }
+ catch (Exception ex)
+ {
+ LogHelper.WriteLogToFile($"调整TimerContainer尺寸失败: {ex.Message}", LogHelper.LogType.Error);
+ }
+ }
+
#endregion
@@ -787,6 +847,16 @@ namespace Ink_Canvas
{
ShowNotification($"系统DPI发生变化,从 {e.OldDpi.DpiScaleX}x{e.OldDpi.DpiScaleY} 变化为 {e.NewDpi.DpiScaleX}x{e.NewDpi.DpiScaleY}");
+ // 如果TimerContainer可见,调整其尺寸
+ Dispatcher.Invoke(() =>
+ {
+ var timerContainer = FindName("TimerContainer") as FrameworkElement;
+ if (timerContainer != null && timerContainer.Visibility == Visibility.Visible)
+ {
+ AdjustTimerContainerSize();
+ }
+ });
+
new Thread(() =>
{
var isFloatingBarOutsideScreen = false;
diff --git a/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs b/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs
index cfbbcf2c..0fc0c2d0 100644
--- a/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs
+++ b/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs
@@ -1033,6 +1033,10 @@ namespace Ink_Canvas
{
// 每次打开计时器窗口时重置计时器
TimerControl.ResetTimerState();
+
+ // 根据DPI缩放因子调整TimerContainer的尺寸
+ AdjustTimerContainerSize();
+
TimerContainer.Visibility = Visibility.Visible;
if (MinimizedTimerContainer != null)
{
diff --git a/Ink Canvas/Windows/TimerControl.xaml b/Ink Canvas/Windows/TimerControl.xaml
index 02f931f3..496694a3 100644
--- a/Ink Canvas/Windows/TimerControl.xaml
+++ b/Ink Canvas/Windows/TimerControl.xaml
@@ -34,7 +34,11 @@
-
+
1.25 || dpiScaleY > 1.25)
+ {
+ // 使用较小的缩放因子来限制最大尺寸
+ double scaleFactor = Math.Min(dpiScaleX, dpiScaleY);
+
+ if (MainViewController != null)
+ {
+ // 计算目标物理像素大小(约1350x750物理像素)
+ // 然后转换为逻辑像素
+ double targetPhysicalWidth = 1350;
+ double targetPhysicalHeight = 750;
+
+ // 转换为逻辑像素
+ double maxWidth = targetPhysicalWidth / scaleFactor;
+ double maxHeight = targetPhysicalHeight / scaleFactor;
+
+ // 确保不会小于原始尺寸的70%
+ maxWidth = Math.Max(maxWidth, 900 * 0.7);
+ maxHeight = Math.Max(maxHeight, 500 * 0.7);
+
+ MainViewController.MaxWidth = maxWidth;
+ MainViewController.MaxHeight = maxHeight;
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ LogHelper.WriteLogToFile($"调整计时器窗口DPI尺寸失败: {ex.Message}", LogHelper.LogType.Error);
+ }
}
private void TimerControl_Unloaded(object sender, RoutedEventArgs e)