Skip to content

Commit d03d598

Browse files
committed
fix: 横屏时窗口可能跑到外面去
1 parent 98d25e8 commit d03d598

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

MaiChartManager/Browser.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,22 @@ public Browser(string? loopbackUrl = null)
2828
webView21.DefaultBackgroundColor = Color.Transparent;
2929
IapManager.BindToForm(this);
3030

31-
// 竖屏显示器时,限制窗口高度不超过显示器宽度的 2/3
31+
// 限制窗口高度
3232
var landscape = Screen.AllScreens.FirstOrDefault(s => s.WorkingArea.Width >= s.WorkingArea.Height);
3333
if (landscape == null)
3434
{
35+
// 竖屏显示器时,限制窗口高度不超过显示器宽度的 2/3
3536
var portrait = Screen.PrimaryScreen ?? Screen.AllScreens[0];
3637
var maxHeight = portrait.WorkingArea.Width * 2 / 3;
3738
if (Height > maxHeight)
3839
Height = maxHeight;
3940
}
41+
else
42+
{
43+
var maxHeight = landscape.WorkingArea.Height;
44+
if (Height > maxHeight)
45+
Height = maxHeight;
46+
}
4047

4148
StartPosition = FormStartPosition.Manual;
4249
Location = WebViewHelper.CalculatePosition(Width, Height);

MaiChartManager/WebViewHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static Point CalculatePosition(int width, int height)
1515
var area = landscape.WorkingArea;
1616
return new Point(
1717
area.X + (area.Width - width) / 2,
18-
area.Y + (area.Height - height) / 2
18+
Math.Max(area.Y, area.Y + (area.Height - height) / 2)
1919
);
2020
}
2121

@@ -25,7 +25,7 @@ public static Point CalculatePosition(int width, int height)
2525
var squareTop = pArea.Bottom - squareSize;
2626
return new Point(
2727
pArea.X + (squareSize - width) / 2,
28-
squareTop + (squareSize - height) / 2
28+
Math.Max(pArea.Y, squareTop + (squareSize - height) / 2)
2929
);
3030
}
3131

0 commit comments

Comments
 (0)