* UILine: 修复了文本为空不显示的问题

This commit is contained in:
Sunny 2022-01-10 21:14:10 +08:00
parent 8bccba294d
commit 1e97e2c9de
2 changed files with 56 additions and 45 deletions

Binary file not shown.

View File

@ -18,6 +18,7 @@
* *
* 2020-01-01: V2.2.0 * 2020-01-01: V2.2.0
* 2022-01-05: V3.0.9 线 * 2022-01-05: V3.0.9 线
* 2022-01-10: V3.1.0
******************************************************************************/ ******************************************************************************/
using System; using System;
@ -160,9 +161,7 @@ namespace Sunny.UI
protected override void OnPaintFore(Graphics g, GraphicsPath path) protected override void OnPaintFore(Graphics g, GraphicsPath path)
{ {
if (string.IsNullOrEmpty(Text)) return; SizeF sf = new SizeF(0, 0);
SizeF sf = g.MeasureString(Text, Font);
float x = 0; float x = 0;
Pen pen = new Pen(rectColor, lineSize); Pen pen = new Pen(rectColor, lineSize);
if (LineDashStyle != UILineDashStyle.None) if (LineDashStyle != UILineDashStyle.None)
@ -170,8 +169,13 @@ namespace Sunny.UI
pen.DashStyle = (DashStyle)((int)LineDashStyle); pen.DashStyle = (DashStyle)((int)LineDashStyle);
} }
if (Direction == LineDirection.Horizontal) if (Direction == LineDirection.Horizontal)
{ {
if (Text.IsValid())
{
sf = g.MeasureString(Text, Font);
switch (TextAlign) switch (TextAlign)
{ {
case ContentAlignment.BottomLeft: case ContentAlignment.BottomLeft:
@ -213,8 +217,11 @@ namespace Sunny.UI
g.DrawString(Text, Font, foreColor, Width - sf.Width - TextInterval - 2 - Padding.Right, (Height - lineSize) / 2.0f - sf.Height); g.DrawString(Text, Font, foreColor, Width - sf.Width - TextInterval - 2 - Padding.Right, (Height - lineSize) / 2.0f - sf.Height);
break; break;
} }
}
int top = (Height - lineSize) / 2; int top = (Height - lineSize) / 2;
if (Text.IsValid())
{
switch (TextAlign) switch (TextAlign)
{ {
case ContentAlignment.MiddleLeft: case ContentAlignment.MiddleLeft:
@ -227,6 +234,11 @@ namespace Sunny.UI
g.DrawLine(pen, Padding.Left, top, Width - 2 - Padding.Left - Padding.Right, top); g.DrawLine(pen, Padding.Left, top, Width - 2 - Padding.Left - Padding.Right, top);
break; break;
} }
}
else
{
g.DrawLine(pen, Padding.Left, top, Width - 2 - Padding.Left - Padding.Right, top);
}
switch (startCap) switch (startCap)
{ {
@ -268,7 +280,6 @@ namespace Sunny.UI
} }
pen.Dispose(); pen.Dispose();
} }
UILineDashStyle lineDashStyle = UILineDashStyle.None; UILineDashStyle lineDashStyle = UILineDashStyle.None;