* UILine: 修复了文本为空不显示的问题
This commit is contained in:
parent
8bccba294d
commit
1e97e2c9de
Binary file not shown.
@ -18,6 +18,7 @@
|
||||
*
|
||||
* 2020-01-01: V2.2.0 增加文件说明
|
||||
* 2022-01-05: V3.0.9 增加线的样式,支持透明背景
|
||||
* 2022-01-10: V3.1.0 修复了文本为空不显示的问题
|
||||
******************************************************************************/
|
||||
|
||||
using System;
|
||||
@ -160,9 +161,7 @@ namespace Sunny.UI
|
||||
|
||||
protected override void OnPaintFore(Graphics g, GraphicsPath path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Text)) return;
|
||||
|
||||
SizeF sf = g.MeasureString(Text, Font);
|
||||
SizeF sf = new SizeF(0, 0);
|
||||
float x = 0;
|
||||
Pen pen = new Pen(rectColor, lineSize);
|
||||
if (LineDashStyle != UILineDashStyle.None)
|
||||
@ -170,62 +169,75 @@ namespace Sunny.UI
|
||||
pen.DashStyle = (DashStyle)((int)LineDashStyle);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (Direction == LineDirection.Horizontal)
|
||||
{
|
||||
switch (TextAlign)
|
||||
if (Text.IsValid())
|
||||
{
|
||||
case ContentAlignment.BottomLeft:
|
||||
g.DrawString(Text, Font, foreColor, Padding.Left + TextInterval + 2, (Height + lineSize) / 2.0f);
|
||||
break;
|
||||
sf = g.MeasureString(Text, Font);
|
||||
switch (TextAlign)
|
||||
{
|
||||
case ContentAlignment.BottomLeft:
|
||||
g.DrawString(Text, Font, foreColor, Padding.Left + TextInterval + 2, (Height + lineSize) / 2.0f);
|
||||
break;
|
||||
|
||||
case ContentAlignment.MiddleLeft:
|
||||
x = Padding.Left + TextInterval;
|
||||
g.DrawString(Text, Font, foreColor, Padding.Left + TextInterval + 2, (Height - sf.Height) / 2);
|
||||
break;
|
||||
case ContentAlignment.MiddleLeft:
|
||||
x = Padding.Left + TextInterval;
|
||||
g.DrawString(Text, Font, foreColor, Padding.Left + TextInterval + 2, (Height - sf.Height) / 2);
|
||||
break;
|
||||
|
||||
case ContentAlignment.TopLeft:
|
||||
g.DrawString(Text, Font, foreColor, Padding.Left + TextInterval + 2, (Height - lineSize) / 2.0f - sf.Height);
|
||||
break;
|
||||
case ContentAlignment.TopLeft:
|
||||
g.DrawString(Text, Font, foreColor, Padding.Left + TextInterval + 2, (Height - lineSize) / 2.0f - sf.Height);
|
||||
break;
|
||||
|
||||
case ContentAlignment.BottomCenter:
|
||||
g.DrawString(Text, Font, foreColor, (Width - sf.Width) / 2, (Height + lineSize) / 2.0f);
|
||||
break;
|
||||
case ContentAlignment.BottomCenter:
|
||||
g.DrawString(Text, Font, foreColor, (Width - sf.Width) / 2, (Height + lineSize) / 2.0f);
|
||||
break;
|
||||
|
||||
case ContentAlignment.MiddleCenter:
|
||||
x = (Width - sf.Width) / 2 - 2;
|
||||
g.DrawString(Text, Font, foreColor, (Width - sf.Width) / 2, (Height - sf.Height) / 2);
|
||||
break;
|
||||
case ContentAlignment.MiddleCenter:
|
||||
x = (Width - sf.Width) / 2 - 2;
|
||||
g.DrawString(Text, Font, foreColor, (Width - sf.Width) / 2, (Height - sf.Height) / 2);
|
||||
break;
|
||||
|
||||
case ContentAlignment.TopCenter:
|
||||
g.DrawString(Text, Font, foreColor, (Width - sf.Width) / 2, (Height - lineSize) / 2.0f - sf.Height);
|
||||
break;
|
||||
case ContentAlignment.TopCenter:
|
||||
g.DrawString(Text, Font, foreColor, (Width - sf.Width) / 2, (Height - lineSize) / 2.0f - sf.Height);
|
||||
break;
|
||||
|
||||
case ContentAlignment.BottomRight:
|
||||
g.DrawString(Text, Font, foreColor, Width - sf.Width - TextInterval - 2 - Padding.Right, (Height + lineSize) / 2.0f);
|
||||
break;
|
||||
case ContentAlignment.BottomRight:
|
||||
g.DrawString(Text, Font, foreColor, Width - sf.Width - TextInterval - 2 - Padding.Right, (Height + lineSize) / 2.0f);
|
||||
break;
|
||||
|
||||
case ContentAlignment.MiddleRight:
|
||||
x = Width - sf.Width - TextInterval - 4 - Padding.Right;
|
||||
g.DrawString(Text, Font, foreColor, Width - sf.Width - TextInterval - 2 - Padding.Right, (Height - sf.Height) / 2);
|
||||
break;
|
||||
case ContentAlignment.MiddleRight:
|
||||
x = Width - sf.Width - TextInterval - 4 - Padding.Right;
|
||||
g.DrawString(Text, Font, foreColor, Width - sf.Width - TextInterval - 2 - Padding.Right, (Height - sf.Height) / 2);
|
||||
break;
|
||||
|
||||
case ContentAlignment.TopRight:
|
||||
g.DrawString(Text, Font, foreColor, Width - sf.Width - TextInterval - 2 - Padding.Right, (Height - lineSize) / 2.0f - sf.Height);
|
||||
break;
|
||||
case ContentAlignment.TopRight:
|
||||
g.DrawString(Text, Font, foreColor, Width - sf.Width - TextInterval - 2 - Padding.Right, (Height - lineSize) / 2.0f - sf.Height);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int top = (Height - lineSize) / 2;
|
||||
switch (TextAlign)
|
||||
if (Text.IsValid())
|
||||
{
|
||||
case ContentAlignment.MiddleLeft:
|
||||
case ContentAlignment.MiddleCenter:
|
||||
case ContentAlignment.MiddleRight:
|
||||
g.DrawLine(pen, Padding.Left, top, x, top);
|
||||
g.DrawLine(pen, x + sf.Width + 2, top, Width - 2 - Padding.Left - Padding.Right, top);
|
||||
break;
|
||||
default:
|
||||
g.DrawLine(pen, Padding.Left, top, Width - 2 - Padding.Left - Padding.Right, top);
|
||||
break;
|
||||
switch (TextAlign)
|
||||
{
|
||||
case ContentAlignment.MiddleLeft:
|
||||
case ContentAlignment.MiddleCenter:
|
||||
case ContentAlignment.MiddleRight:
|
||||
g.DrawLine(pen, Padding.Left, top, x, top);
|
||||
g.DrawLine(pen, x + sf.Width + 2, top, Width - 2 - Padding.Left - Padding.Right, top);
|
||||
break;
|
||||
default:
|
||||
g.DrawLine(pen, Padding.Left, top, Width - 2 - Padding.Left - Padding.Right, top);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g.DrawLine(pen, Padding.Left, top, Width - 2 - Padding.Left - Padding.Right, top);
|
||||
}
|
||||
|
||||
switch (startCap)
|
||||
@ -268,7 +280,6 @@ namespace Sunny.UI
|
||||
}
|
||||
|
||||
pen.Dispose();
|
||||
|
||||
}
|
||||
|
||||
UILineDashStyle lineDashStyle = UILineDashStyle.None;
|
||||
|
Loading…
x
Reference in New Issue
Block a user