* UIForm: 修改标题栏文字与控制按钮绘制重叠的问题

This commit is contained in:
Sunny 2024-02-19 17:42:10 +08:00
parent b78aed01f7
commit 79cb09618b
2 changed files with 46 additions and 34 deletions

View File

@ -53,6 +53,7 @@
* 2023-11-19: V3.5.2 ShowShadow边框阴影打开ShowRadius显示圆角关闭 * 2023-11-19: V3.5.2 ShowShadow边框阴影打开ShowRadius显示圆角关闭
* 2023-12-04: V3.6.1 Style后BackColor未保存的问题 * 2023-12-04: V3.6.1 Style后BackColor未保存的问题
* 2023-12-13: V3.6.2 UIPage的Init和Final加载逻辑 * 2023-12-13: V3.6.2 UIPage的Init和Final加载逻辑
* 2023-02-19: V3.6.3
******************************************************************************/ ******************************************************************************/
using System; using System;
@ -1019,6 +1020,28 @@ namespace Sunny.UI
return; return;
} }
if (ShowTitleIcon && Icon != null)
{
using (Image image = IconToImage(Icon))
{
e.Graphics.DrawImage(image, 6, (TitleHeight - 24) / 2, 24, 24);
}
}
if (TextAlignment == StringAlignment.Center)
{
e.Graphics.DrawString(Text, TitleFont, titleForeColor, new Rectangle(0, 0, Width, TitleHeight), ContentAlignment.MiddleCenter);
}
else
{
e.Graphics.DrawString(Text, TitleFont, titleForeColor, new Rectangle(6 + (ShowTitleIcon && Icon != null ? 26 : 0), 0, Width, TitleHeight), ContentAlignment.MiddleLeft);
}
if (ControlBoxLeft != Width)
{
e.Graphics.FillRectangle(TitleColor, new Rectangle(ControlBoxLeft, 1, Width, TitleHeight - 2));
}
e.Graphics.SetHighQuality(); e.Graphics.SetHighQuality();
if (ControlBox) if (ControlBox)
{ {
@ -1148,23 +1171,6 @@ namespace Sunny.UI
} }
e.Graphics.SetDefaultQuality(); e.Graphics.SetDefaultQuality();
if (ShowTitleIcon && Icon != null)
{
using (Image image = IconToImage(Icon))
{
e.Graphics.DrawImage(image, 6, (TitleHeight - 24) / 2, 24, 24);
}
}
if (TextAlignment == StringAlignment.Center)
{
e.Graphics.DrawString(Text, TitleFont, titleForeColor, new Rectangle(0, 0, Width, TitleHeight), ContentAlignment.MiddleCenter);
}
else
{
e.Graphics.DrawString(Text, TitleFont, titleForeColor, new Rectangle(6 + (ShowTitleIcon && Icon != null ? 26 : 0), 0, Width, TitleHeight), ContentAlignment.MiddleLeft);
}
} }
private Image IconToImage(Icon icon) private Image IconToImage(Icon icon)

View File

@ -875,7 +875,30 @@ namespace Sunny.UI
return; return;
} }
if (ShowTitleIcon && Icon != null)
{
using (Image image = IconToImage(Icon))
{
e.Graphics.DrawImage(image, 6, (TitleHeight - 24) / 2, 24, 24);
}
}
if (TextAlignment == StringAlignment.Center)
{
e.Graphics.DrawString(Text, TitleFont, titleForeColor, new Rectangle(0, 0, Width, TitleHeight), ContentAlignment.MiddleCenter);
}
else
{
e.Graphics.DrawString(Text, TitleFont, titleForeColor, new Rectangle(6 + (ShowTitleIcon && Icon != null ? 26 : 0), 0, Width, TitleHeight), ContentAlignment.MiddleLeft);
}
e.Graphics.SetHighQuality(); e.Graphics.SetHighQuality();
if (ControlBoxLeft != Width)
{
e.Graphics.FillRectangle(TitleColor, new Rectangle(ControlBoxLeft, 1, Width, TitleHeight - 2));
}
if (ControlBox) if (ControlBox)
{ {
if (InControlBox) if (InControlBox)
@ -992,23 +1015,6 @@ namespace Sunny.UI
} }
e.Graphics.SetDefaultQuality(); e.Graphics.SetDefaultQuality();
if (ShowTitleIcon && Icon != null)
{
using (Image image = IconToImage(Icon))
{
e.Graphics.DrawImage(image, 6, (TitleHeight - 24) / 2, 24, 24);
}
}
if (TextAlignment == StringAlignment.Center)
{
e.Graphics.DrawString(Text, TitleFont, titleForeColor, new Rectangle(0, 0, Width, TitleHeight), ContentAlignment.MiddleCenter);
}
else
{
e.Graphics.DrawString(Text, TitleFont, titleForeColor, new Rectangle(6 + (ShowTitleIcon && Icon != null ? 26 : 0), 0, Width, TitleHeight), ContentAlignment.MiddleLeft);
}
} }
private StringAlignment textAlignment = StringAlignment.Near; private StringAlignment textAlignment = StringAlignment.Near;