This commit is contained in:
2025-12-27 22:57:22 +08:00
parent ab6425e0d9
commit e972adfbcb
4 changed files with 127 additions and 1 deletions
+48
View File
@@ -50,6 +50,54 @@ namespace Ink_Canvas.Windows
// 监听卸载事件,清理资源
Unloaded += TimerControl_Unloaded;
// 监听加载事件,调整DPI相关的尺寸
Loaded += TimerControl_Loaded;
}
private void TimerControl_Loaded(object sender, RoutedEventArgs e)
{
// 根据DPI缩放因子调整Viewbox的最大尺寸,确保在高DPI屏幕上不会过大
try
{
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);
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)