* UIGroupBox: 解决BackColor,FillColor设置为透明时,标题下面会出现横线

This commit is contained in:
Sunny 2023-07-11 23:25:36 +08:00
parent 22da0fccbd
commit b95d430599
3 changed files with 139 additions and 3 deletions

View File

@ -300,6 +300,83 @@ namespace Sunny.UI
return path; return path;
} }
/// <summary>
/// 创建圆角路径
/// </summary>
/// <param name="rect">区域</param>
/// <param name="radius">圆角大小</param>
/// <param name="radiusSides">圆角的方位</param>
/// <param name="lineSize">线宽</param>
/// <returns></returns>
internal static GraphicsPath CreateRoundedRectanglePathWithoutTop(this Rectangle rect, int radius, UICornerRadiusSides radiusSides, int lineSize = 1)
{
GraphicsPath path;
if (radiusSides == UICornerRadiusSides.None || radius == 0)
{
path = new GraphicsPath();
path.AddLine(new Point(rect.X, rect.Y), new Point(rect.X, rect.Y + rect.Height));
path.AddLine(new Point(rect.X, rect.Y + rect.Height), new Point(rect.X + rect.Width, rect.Y + rect.Height));
path.AddLine(new Point(rect.X + rect.Width, rect.Y + rect.Height), new Point(rect.X + rect.Width, rect.Y));
}
else
{
//IsRadius为True时显示左上圆角
bool RadiusLeftTop = radiusSides.GetValue(UICornerRadiusSides.LeftTop);
//IsRadius为True时显示左下圆角
bool RadiusLeftBottom = radiusSides.GetValue(UICornerRadiusSides.LeftBottom);
//IsRadius为True时显示右上圆角
bool RadiusRightTop = radiusSides.GetValue(UICornerRadiusSides.RightTop);
//IsRadius为True时显示右下圆角
bool RadiusRightBottom = radiusSides.GetValue(UICornerRadiusSides.RightBottom);
path = rect.CreateRoundedRectanglePathWithoutTop(radius, RadiusLeftTop, RadiusRightTop, RadiusRightBottom, RadiusLeftBottom, lineSize);
}
return path;
}
internal static GraphicsPath CreateRoundedRectanglePathWithoutTop(this Rectangle rect, int radius,
bool cornerLeftTop = true, bool cornerRightTop = true, bool cornerRightBottom = true, bool cornerLeftBottom = true,
int lineSize = 1)
{
GraphicsPath path = new GraphicsPath();
if ((!cornerLeftTop && !cornerRightTop && !cornerRightBottom && !cornerLeftBottom) || radius <= 0)
{
path.AddLine(new Point(rect.X, rect.Y), new Point(rect.X, rect.Y + rect.Height));
path.AddLine(new Point(rect.X, rect.Y + rect.Height), new Point(rect.X + rect.Width, rect.Y + rect.Height));
path.AddLine(new Point(rect.X + rect.Width, rect.Y + rect.Height), new Point(rect.X + rect.Width, rect.Y));
}
else
{
radius *= lineSize;
if (cornerRightTop)
path.AddArc(rect.X + rect.Width - radius, rect.Y, radius, radius, 270, 90);
else
path.AddLine(new Point(rect.X + rect.Width - 1, rect.Y), new Point(rect.X + rect.Width, rect.Y));
if (cornerRightBottom)
path.AddArc(rect.X + rect.Width - radius, rect.Y + rect.Height - radius, radius, radius, 0, 90);
else
path.AddLine(new Point(rect.X + rect.Width, rect.Y + rect.Height), new Point(rect.X + rect.Width, rect.Y + rect.Height));
if (cornerLeftBottom)
path.AddArc(rect.X, rect.Bottom - radius, radius, radius, 90, 90);
else
path.AddLine(new Point(rect.X + 1, rect.Y + rect.Height), new Point(rect.X, rect.Y + rect.Height));
if (cornerLeftTop)
path.AddArc(rect.X, rect.Y, radius, radius, 180, 90);
else
path.AddLine(new Point(rect.X, rect.Y + 1), new Point(rect.X, rect.Y));
//path.CloseFigure();
}
return path;
}
/// <summary> /// <summary>
/// 绘图路径 /// 绘图路径
/// </summary> /// </summary>

View File

@ -368,7 +368,29 @@ namespace Sunny.UI
int idx = VBar.Value; int idx = VBar.Value;
if (idx < 0) idx = 0; if (idx < 0) idx = 0;
if (idx >= RowCount) idx = RowCount - 1; if (idx >= RowCount) idx = RowCount - 1;
FirstDisplayedScrollingRowIndex = idx;
int lastFrozen = 0;
if (Rows[0].Frozen)
{
for (int i = 0; i < Rows.Count; i++)
{
if (Rows[i].Frozen)
{
lastFrozen = i;
}
else
{
break;
}
}
}
if (Rows[0].Frozen)
{
}
FirstDisplayedScrollingRowIndex = Math.Max(idx, lastFrozen);
} }
private void HorizontalScrollBar_ValueChanged(object sender, EventArgs e) private void HorizontalScrollBar_ValueChanged(object sender, EventArgs e)

View File

@ -20,6 +20,7 @@
* 2020-04-25: V2.2.4 * 2020-04-25: V2.2.4
* 2022-05-30: V3.1.9 Padding设置 * 2022-05-30: V3.1.9 Padding设置
* 2023-05-13: V3.3.6 DrawString函数 * 2023-05-13: V3.3.6 DrawString函数
* 2023-07-11: V3.4.0 BackColor,FillColor设置为透明时线
******************************************************************************/ ******************************************************************************/
using System; using System;
@ -56,8 +57,22 @@ namespace Sunny.UI
/// <param name="path">绘图路径</param> /// <param name="path">绘图路径</param>
protected override void OnPaintRect(Graphics g, GraphicsPath path) protected override void OnPaintRect(Graphics g, GraphicsPath path)
{ {
path = new Rectangle(0, TitleTop, Width - 1, Height - _titleTop - 1).CreateRoundedRectanglePath(Radius, RadiusSides); if (RectSides == ToolStripStatusLabelBorderSides.None)
base.OnPaintRect(g, path); {
return;
}
var rect = new Rectangle(0, TitleTop, Width - 1, Height - _titleTop - 1);
if (Text.IsValid())
{
path = rect.CreateRoundedRectanglePathWithoutTop(Radius, RadiusSides, RectSize);
g.DrawPath(GetRectColor(), path, true, RectSize);
}
else
{
path = rect.CreateRoundedRectanglePath(Radius, RadiusSides, RectSize);
g.DrawPath(GetRectColor(), path, true, RectSize);
}
} }
/// <summary> /// <summary>
@ -67,7 +82,29 @@ namespace Sunny.UI
/// <param name="path">绘图路径</param> /// <param name="path">绘图路径</param>
protected override void OnPaintFore(Graphics g, GraphicsPath path) protected override void OnPaintFore(Graphics g, GraphicsPath path)
{ {
Size size = TextRenderer.MeasureText(Text, Font);
g.DrawString(Text, Font, ForeColor, FillColor, new Rectangle(TitleInterval, 0, Width - TitleInterval * 2, TitleTop * 2), TitleAlignment); g.DrawString(Text, Font, ForeColor, FillColor, new Rectangle(TitleInterval, 0, Width - TitleInterval * 2, TitleTop * 2), TitleAlignment);
if (RectSides.GetValue(ToolStripStatusLabelBorderSides.Top))
{
if (RadiusSides.GetValue(UICornerRadiusSides.LeftTop))
{
g.DrawLine(RectColor, Radius / 2 * RectSize, TitleTop, TitleInterval, TitleTop, true, RectSize);
}
else
{
g.DrawLine(RectColor, 0, TitleTop, TitleInterval, TitleTop, true, RectSize);
}
if (RadiusSides.GetValue(UICornerRadiusSides.RightTop))
{
g.DrawLine(RectColor, TitleInterval + size.Width, TitleTop, Width - Radius / 2 * RectSize, TitleTop, true, RectSize);
}
else
{
g.DrawLine(RectColor, TitleInterval + size.Width, TitleTop, Width, TitleTop, true, RectSize);
}
}
} }
private int _titleTop = 16; private int _titleTop = 16;