修复暂停状态下遮罩层不显示暂停字样的问题

This commit is contained in:
zqm
2025-10-30 08:45:23 +08:00
parent 7984434243
commit 8ea1829cf2

View File

@@ -108,62 +108,83 @@ namespace JoyD.Windows.CS.Toprie
{
try
{
Console.WriteLine($"UpdateMaskDisplay called, _isImageUpdatePaused: {_isImageUpdatePaused}, maskImageBox: {maskImageBox}, maskImageBox.Size: {maskImageBox.Width}x{maskImageBox.Height}");
if (_isImageUpdatePaused)
{
// 创建一个与maskImageBox大小相同的位图
Bitmap bitmap = new Bitmap(maskImageBox.Width, maskImageBox.Height);
// 确保maskImageBox大小有效
int width = Math.Max(100, maskImageBox.Width);
int height = Math.Max(100, maskImageBox.Height);
Console.WriteLine($"Creating bitmap with size: {width}x{height}");
// 创建一个位图
Bitmap bitmap = new Bitmap(width, height);
using (Graphics g = Graphics.FromImage(bitmap))
{
// 设置高质量绘制
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
// 设置半透明背景
using (Brush brush = new SolidBrush(Color.FromArgb(100, Color.Black)))
using (Brush brush = new SolidBrush(Color.FromArgb(150, Color.Black)))
{
g.FillRectangle(brush, 0, 0, bitmap.Width, bitmap.Height);
}
// 设置文本样式
Font font = new Font("微软雅黑", 36, FontStyle.Bold);
Font font = new Font("微软雅黑", 48, FontStyle.Bold);
Brush textBrush = new SolidBrush(Color.White);
StringFormat format = new StringFormat();
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Center;
// 绘制"暂停"文字
Console.WriteLine("Drawing '暂停' text");
g.DrawString("暂停", font, textBrush,
new Rectangle(0, 0, bitmap.Width, bitmap.Height), format);
}
// 在UI线程上更新maskImageBox
Console.WriteLine("Updating maskImageBox image");
if (maskImageBox.InvokeRequired)
{
maskImageBox.Invoke(new Action(() =>
{
maskImageBox.Image = bitmap;
maskImageBox.Visible = true;
Console.WriteLine("maskImageBox updated via Invoke");
}));
}
else
{
maskImageBox.Image = bitmap;
maskImageBox.Visible = true;
Console.WriteLine("maskImageBox updated directly");
}
}
else
{
// 清除遮罩
Console.WriteLine("Clearing maskImageBox image");
if (maskImageBox.InvokeRequired)
{
maskImageBox.Invoke(new Action(() =>
{
maskImageBox.Image = null;
Console.WriteLine("maskImageBox cleared via Invoke");
}));
}
else
{
maskImageBox.Image = null;
Console.WriteLine("maskImageBox cleared directly");
}
}
}
catch (Exception ex)
{
Console.WriteLine($"更新遮罩显示时出错: {ex.Message}");
Console.WriteLine($"更新遮罩显示时出错: {ex.Message}, StackTrace: {ex.StackTrace}");
}
}