From 6079ddd2a6522fe6b109afa6c907b3ad2ed116f5 Mon Sep 17 00:00:00 2001 From: jasonchenwork Date: Thu, 8 May 2025 16:49:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E7=95=AB=E9=9D=A2=E8=9E=A2?= =?UTF-8?q?=E5=B9=95=E8=A7=A3=E6=9E=90=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VideoPlayerForm.cs | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/VideoPlayerForm.cs b/VideoPlayerForm.cs index d4c2775..0f1dd95 100644 --- a/VideoPlayerForm.cs +++ b/VideoPlayerForm.cs @@ -399,7 +399,7 @@ namespace DualScreenDemo throw; // Rethrow the exception to handle it further up the call stack } } - + // 同步畫面事件 public void SyncToPrimaryMonitor() { PrimaryForm.Instance.primaryScreenPanel.Visible = true; @@ -441,11 +441,35 @@ namespace DualScreenDemo // Console.WriteLine("VMR9 is not initialized."); return; } + int designWidth = 1620; + int designHeight = 1080; + int actualWidth = PrimaryForm.Instance.primaryScreenPanel.Width; + int actualHeight = PrimaryForm.Instance.primaryScreenPanel.Height; + + // 等比例縮放(不會超出,fit) + float scaleX = (float)actualWidth / designWidth; + float scaleY = (float)actualHeight / designHeight; + float scale = Math.Min(scaleX, scaleY); + + // 計算縮放後的尺寸(但起點仍是 0,0) + int newWidth = (int)(designWidth * scale); + int newHeight = (int)(designHeight * scale); + + // trash location with trash flexible of screen size. + if (actualWidth == 1024){ + newWidth = (int)(newWidth * 0.84f); + } + else if (actualWidth == 1440){ + newWidth = (int)(newWidth * 0.9f); + } videoWindowPrimary = (IVideoWindow)videoRendererPrimary; - videoWindowPrimary.put_Owner(PrimaryForm.Instance.primaryScreenPanel.Handle); // 设置为 primaryScreenPanel 的句柄 + videoWindowPrimary.put_Owner(PrimaryForm.Instance.primaryScreenPanel.Handle); videoWindowPrimary.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipChildren); - videoWindowPrimary.SetWindowPosition(0, 0, 1620, 1080); // 调整视频窗口大小以填满黑色区域 + + // ⬅ 左上角對齊(固定從 0,0 開始) + videoWindowPrimary.SetWindowPosition(0, 0, newWidth, newHeight); + videoWindowPrimary.put_Visible(OABool.True); // Console.WriteLine("Video window configured successfully.");