* UITitlePanel: 标题栏文字位置属性由TextAlign改为TextAlignment

This commit is contained in:
Sunny 2023-05-12 11:03:53 +08:00
parent 756877cc0b
commit 05b674e3ba
2 changed files with 25 additions and 14 deletions

View File

@ -118,6 +118,14 @@ namespace Sunny.UI
TextRenderer.DrawText(g, text, font, new Point(left, top), color); TextRenderer.DrawText(g, text, font, new Point(left, top), color);
} }
public static void DrawString(this Graphics g, string text, Font font, Color color, Rectangle rect, HorizontalAlignment horizontalAlignment, int offsetX = 0, int offsetY = 0)
{
StringAlignment alignment = StringAlignment.Center;
if (horizontalAlignment == HorizontalAlignment.Left) alignment = StringAlignment.Near;
if (horizontalAlignment == HorizontalAlignment.Right) alignment = StringAlignment.Far;
g.DrawString(text, font, color, rect, alignment, StringAlignment.Center, offsetX, offsetY);
}
/// <summary> /// <summary>
/// 绘制字符串 /// 绘制字符串
/// </summary> /// </summary>

View File

@ -23,6 +23,7 @@
* 2022-05-30: V3.1.9 Padding设置 * 2022-05-30: V3.1.9 Padding设置
* 2022-10-28: V3.2.6 * 2022-10-28: V3.2.6
* 2023-05-02: V3.3.6 * 2023-05-02: V3.3.6
* 2023-05-12: V3.3.6 TextAlign改为TextAlignment
******************************************************************************/ ******************************************************************************/
using System; using System;
@ -103,7 +104,7 @@ namespace Sunny.UI
/// 文字对齐方向 /// 文字对齐方向
/// </summary> /// </summary>
[DefaultValue(HorizontalAlignment.Center)] [DefaultValue(HorizontalAlignment.Center)]
[Description("文字对齐方向"), Category("SunnyUI")] [Description("文字对齐方向"), Category("SunnyUI"), Browsable(false)]
public HorizontalAlignment TextAlign public HorizontalAlignment TextAlign
{ {
get => textAlign; get => textAlign;
@ -165,20 +166,22 @@ namespace Sunny.UI
color = Enabled ? TitleForeColor : UIFontColor.Regular; color = Enabled ? TitleForeColor : UIFontColor.Regular;
SizeF sf = g.MeasureString(Text, Font); SizeF sf = g.MeasureString(Text, Font);
switch (TextAlign) g.DrawString(Text, Font, color, new Rectangle(_titleInterval, 0, Width - _titleInterval * 2 - (ShowCollapse || ShowClose ? 24 : 0), TitleHeight), TextAlignment);
{
case HorizontalAlignment.Left:
g.DrawString(Text, Font, color, _titleInterval, (TitleHeight - sf.Height) / 2.0f);
break;
case HorizontalAlignment.Center: //switch (TextAlign)
g.DrawString(Text, Font, color, (Width - sf.Width) / 2.0f, (TitleHeight - sf.Height) / 2.0f); //{
break; // case HorizontalAlignment.Left:
// g.DrawString(Text, Font, color, _titleInterval, (TitleHeight - sf.Height) / 2.0f);
case HorizontalAlignment.Right: // break;
g.DrawString(Text, Font, color, Width - _titleInterval - sf.Width, (TitleHeight - sf.Height) / 2.0f); //
break; // case HorizontalAlignment.Center:
} // g.DrawString(Text, Font, color, (Width - sf.Width) / 2.0f, (TitleHeight - sf.Height) / 2.0f);
// break;
//
// case HorizontalAlignment.Right:
// g.DrawString(Text, Font, color, Width - _titleInterval - sf.Width, (TitleHeight - sf.Height) / 2.0f);
// break;
//}
if (ShowCollapse) if (ShowCollapse)
{ {