From b95d430599b740846c342c258c454f30f8ac9777 Mon Sep 17 00:00:00 2001 From: Sunny Date: Tue, 11 Jul 2023 23:25:36 +0800 Subject: [PATCH] =?UTF-8?q?*=20UIGroupBox:=20=E8=A7=A3=E5=86=B3BackColor,F?= =?UTF-8?q?illColor=E8=AE=BE=E7=BD=AE=E4=B8=BA=E9=80=8F=E6=98=8E=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E6=A0=87=E9=A2=98=E4=B8=8B=E9=9D=A2=E4=BC=9A=E5=87=BA?= =?UTF-8?q?=E7=8E=B0=E6=A8=AA=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SunnyUI/Common/UGDI.cs | 77 ++++++++++++++++++++++++++++++ SunnyUI/Controls/UIDataGridView.cs | 24 +++++++++- SunnyUI/Controls/UIGroupBox.cs | 41 +++++++++++++++- 3 files changed, 139 insertions(+), 3 deletions(-) diff --git a/SunnyUI/Common/UGDI.cs b/SunnyUI/Common/UGDI.cs index a93fc00a..ba8d8dee 100644 --- a/SunnyUI/Common/UGDI.cs +++ b/SunnyUI/Common/UGDI.cs @@ -300,6 +300,83 @@ namespace Sunny.UI return path; } + /// + /// 创建圆角路径 + /// + /// 区域 + /// 圆角大小 + /// 圆角的方位 + /// 线宽 + /// + 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; + } + /// /// 绘图路径 /// diff --git a/SunnyUI/Controls/UIDataGridView.cs b/SunnyUI/Controls/UIDataGridView.cs index 30021837..df1dccc8 100644 --- a/SunnyUI/Controls/UIDataGridView.cs +++ b/SunnyUI/Controls/UIDataGridView.cs @@ -368,7 +368,29 @@ namespace Sunny.UI int idx = VBar.Value; if (idx < 0) idx = 0; 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) diff --git a/SunnyUI/Controls/UIGroupBox.cs b/SunnyUI/Controls/UIGroupBox.cs index 19512226..c553344c 100644 --- a/SunnyUI/Controls/UIGroupBox.cs +++ b/SunnyUI/Controls/UIGroupBox.cs @@ -20,6 +20,7 @@ * 2020-04-25: V2.2.4 更新主题配置类 * 2022-05-30: V3.1.9 修复Padding设置 * 2023-05-13: V3.3.6 重构DrawString函数 + * 2023-07-11: V3.4.0 解决BackColor,FillColor设置为透明时,标题下面会出现横线 ******************************************************************************/ using System; @@ -56,8 +57,22 @@ namespace Sunny.UI /// 绘图路径 protected override void OnPaintRect(Graphics g, GraphicsPath path) { - path = new Rectangle(0, TitleTop, Width - 1, Height - _titleTop - 1).CreateRoundedRectanglePath(Radius, RadiusSides); - base.OnPaintRect(g, path); + if (RectSides == ToolStripStatusLabelBorderSides.None) + { + 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); + } } /// @@ -67,7 +82,29 @@ namespace Sunny.UI /// 绘图路径 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); + + 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;