From 448d24513c4ee40383ab2fa95a43bf11897c6c7c Mon Sep 17 00:00:00 2001 From: asuper Date: Tue, 17 Oct 2023 11:47:11 +0800 Subject: [PATCH 1/4] =?UTF-8?q?UITitlePanel=E5=A2=9E=E5=8A=A0CollapseDirec?= =?UTF-8?q?tion=E5=B1=9E=E6=80=A7=EF=BC=8C=E6=94=AF=E6=8C=81=E6=A0=87?= =?UTF-8?q?=E9=A2=98=E6=A0=8F=E5=9C=A8=E5=BA=95=E9=83=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SunnyUI/Controls/UITitlePanel.cs | 129 +++++++++++++++++++++++++++---- 1 file changed, 113 insertions(+), 16 deletions(-) diff --git a/SunnyUI/Controls/UITitlePanel.cs b/SunnyUI/Controls/UITitlePanel.cs index a2382009..b9b51922 100644 --- a/SunnyUI/Controls/UITitlePanel.cs +++ b/SunnyUI/Controls/UITitlePanel.cs @@ -67,6 +67,7 @@ namespace Sunny.UI titleColor = UIStyles.Blue.PanelTitleColor; titleForeColor = UIStyles.Blue.PanelTitleForeColor; + collapseDirection = TitlePosition.Top; } /// @@ -136,19 +137,35 @@ namespace Sunny.UI protected override void OnPaintFill(Graphics g, GraphicsPath path) { base.OnPaintFill(g, path); - //IsRadius为True时,显示左上圆角 - bool RadiusLeftTop = RadiusSides.GetValue(UICornerRadiusSides.LeftTop); - //IsRadius为True时,显示右上圆角 - bool RadiusRightTop = RadiusSides.GetValue(UICornerRadiusSides.RightTop); - path = GetTitleFillPath(Radius, TitleHeight, RadiusLeftTop, RadiusRightTop); + bool titleAtTop = CollapseDirection == TitlePosition.Top; + if (titleAtTop) + { + //IsRadius为True时,显示左上圆角 + bool RadiusLeftTop = RadiusSides.GetValue(UICornerRadiusSides.LeftTop); + //IsRadius为True时,显示右上圆角 + bool RadiusRightTop = RadiusSides.GetValue(UICornerRadiusSides.RightTop); + path = GetTitleFillPathTop(Radius, TitleHeight, RadiusLeftTop, RadiusRightTop); + } + else + { + //IsRadius为True时,显示左下圆角 + bool RadiusLeftBottom = RadiusSides.GetValue(UICornerRadiusSides.LeftBottom); + //IsRadius为True时,显示右下圆角 + bool RadiusRightBottom = RadiusSides.GetValue(UICornerRadiusSides.RightBottom); + path = GetTitleFillPathBottom(Radius, TitleHeight, RadiusLeftBottom, RadiusRightBottom); + } Color color = Enabled ? TitleColor : UIDisableColor.Fill; g.FillPath(color, path); if (Height > TitleHeight) - g.DrawLine(RectColor, 0, TitleHeight, Width, TitleHeight); + { + int yPosOfTitleLine = titleAtTop ? TitleHeight : Height - TitleHeight; + g.DrawLine(RectColor, 0, yPosOfTitleLine, Width, yPosOfTitleLine); + } color = Enabled ? TitleForeColor : UIFontColor.Regular; - g.DrawString(Text, Font, color, new Rectangle(_titleInterval, 0, Width - _titleInterval * 2 - (ShowCollapse || ShowClose ? 24 : 0), TitleHeight), TextAlignment); + int yPosOfText = titleAtTop ? 0 : Height - TitleHeight; + g.DrawString(Text, Font, color, new Rectangle(_titleInterval, yPosOfText, Width - _titleInterval * 2 - (ShowCollapse || ShowClose ? 24 : 0), TitleHeight), TextAlignment); if (ShowCollapse) { @@ -160,7 +177,7 @@ namespace Sunny.UI g.FillRectangle(UIStyles.ActiveStyleColor.ButtonFillHoverColor, ControlBoxRect); } - g.DrawFontImage(Collapsed ? 61703 : 61702, 24, SymbolColor, + g.DrawFontImage(Collapsed ^ titleAtTop ? 61703 : 61702, 24, SymbolColor, new Rectangle(ControlBoxRect.Left + 2, ControlBoxRect.Top, ControlBoxRect.Width, ControlBoxRect.Height)); } @@ -231,7 +248,7 @@ namespace Sunny.UI private int _titleInterval = 10; [DefaultValue(10)] - [Description("标题文字局左或者局右时与边框距离"), Category("SunnyUI")] + [Description("标题文字居左或者居右时与边框距离"), Category("SunnyUI")] public int TitleInterval { get => _titleInterval; @@ -242,7 +259,7 @@ namespace Sunny.UI } } - protected GraphicsPath GetTitleFillPath(int radius, int height, bool cornerLeftTop = true, bool cornerRightTop = true) + protected GraphicsPath GetTitleFillPathTop(int radius, int height, bool cornerLeftTop = true, bool cornerRightTop = true) { Rectangle rect = ClientRectangle; GraphicsPath graphicsPath = new GraphicsPath(); @@ -272,11 +289,49 @@ namespace Sunny.UI return graphicsPath; } + protected GraphicsPath GetTitleFillPathBottom(int radius, int height, bool cornerLeftBottom = true, bool cornerRightBottom = true) + { + Rectangle rect = ClientRectangle; + int offset = rect.Height - height; + GraphicsPath graphicsPath = new GraphicsPath(); + if (radius > 0 && ShowRadius) + { + if (cornerLeftBottom) + graphicsPath.AddArc(0, rect.Height - radius - 1, radius, radius, 180f, -90f); + else + graphicsPath.AddLine(new Point(0, rect.Height - 1), new Point(0, rect.Height)); + + if (cornerRightBottom) + graphicsPath.AddArc(rect.Width - radius - 1, rect.Height - radius, radius, radius, 90f, -90f); + else + graphicsPath.AddLine(new Point(rect.Width - 1 - 1, rect.Height), new Point(rect.Width - 1, rect.Height)); + + graphicsPath.AddLine(new Point(rect.Width - 1, rect.Height - radius), new Point(rect.Width - 1, rect.Height - height + 1)); + graphicsPath.AddLine(new Point(radius, rect.Height - height + 1), new Point(0, rect.Height - height + 1)); + + graphicsPath.CloseFigure(); + } + else + { + Point[] points = new Point[] { new Point(0, rect.Height - height), new Point(rect.Width - 1, rect.Height - height), new Point(rect.Width - 1, rect.Height), new Point(0, rect.Height), new Point(0, rect.Height - height), }; + graphicsPath = points.Path(); + } + + return graphicsPath; + } + private Rectangle ControlBoxRect; private void CalcSystemBoxPos() { - ControlBoxRect = new Rectangle(Width - 6 - 28, TitleHeight / 2 - 14, 28, 28); + if (collapseDirection == TitlePosition.Top) + { + ControlBoxRect = new Rectangle(Width - 6 - 28, TitleHeight / 2 - 14, 28, 28); + } + else + { + ControlBoxRect = new Rectangle(Width - 6 - 28, Height - (TitleHeight / 2 - 14) - 28, 28, 28); + } } private bool showCollapse; @@ -293,6 +348,29 @@ namespace Sunny.UI } } + public enum TitlePosition + { + Top, + Bottom, + } + + private TitlePosition collapseDirection; + + [Description("标题在控件中的位置"), Category("SunnyUI"), DefaultValue(TitlePosition.Top)] + public TitlePosition CollapseDirection + { + get => collapseDirection; + set + { + if (value != collapseDirection) + { + collapseDirection = value; + CalcSystemBoxPos(); + Invalidate(); + } + } + } + private bool showClose; [Description("是否打开关闭按钮"), Category("SunnyUI"), DefaultValue(false)] @@ -321,12 +399,20 @@ namespace Sunny.UI if (value) { resizing = true; + if (CollapseDirection == TitlePosition.Bottom) + { + Top += Height - TitleHeight; + } Height = TitleHeight; } else { resizing = false; Height = rowHeight; + if (CollapseDirection == TitlePosition.Bottom) + { + Top -= Height - TitleHeight; + } } collapsed = value; @@ -368,10 +454,14 @@ namespace Sunny.UI protected override void OnMouseDoubleClick(MouseEventArgs e) { - if (ShowCollapse && e.Location.Y <= TitleHeight) + if (ShowCollapse) { - Collapsed = !Collapsed; - OnCollapsed?.Invoke(this, e); + bool titleAtTop = CollapseDirection == TitlePosition.Top; + if ((titleAtTop && e.Location.Y <= TitleHeight) || (!titleAtTop && e.Location.Y >= Height - TitleHeight)) + { + Collapsed = !Collapsed; + OnCollapsed?.Invoke(this, e); + } } base.OnMouseDoubleClick(e); @@ -379,11 +469,18 @@ namespace Sunny.UI private void UITitlePanel_VisibleChanged(object sender, EventArgs e) { + bool titleAtTop = CollapseDirection == TitlePosition.Top; + int childTop; + if (titleAtTop) + childTop = TitleHeight; + else + childTop = 0; foreach (Control control in Controls) { - if (control.Top < TitleHeight) + + if (control.Top < childTop) { - control.Top = TitleHeight + 1; + control.Top = childTop + 1; } } } -- Gitee From 654f8231e538a4372aace26a6eace211b5599391 Mon Sep 17 00:00:00 2001 From: asuper Date: Tue, 17 Oct 2023 11:48:17 +0800 Subject: [PATCH 2/4] =?UTF-8?q?Demo=E4=B8=AD=E5=A2=9E=E5=8A=A0=E5=AF=B9UIT?= =?UTF-8?q?itlePanel.CollapseDirection=E5=B1=9E=E6=80=A7=E7=9A=84=E6=BC=94?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SunnyUI.Demo/Controls/FPanel.Designer.cs | 19 +++++++++++++++++++ SunnyUI.Demo/Controls/FPanel.cs | 5 +++++ 2 files changed, 24 insertions(+) diff --git a/SunnyUI.Demo/Controls/FPanel.Designer.cs b/SunnyUI.Demo/Controls/FPanel.Designer.cs index fed14537..7f0aad2b 100644 --- a/SunnyUI.Demo/Controls/FPanel.Designer.cs +++ b/SunnyUI.Demo/Controls/FPanel.Designer.cs @@ -40,6 +40,7 @@ namespace Sunny.UI.Demo this.uiButton1 = new Sunny.UI.UIButton(); this.uiLine1 = new Sunny.UI.UILine(); this.uiLine2 = new Sunny.UI.UILine(); + this.uiSwitch1 = new Sunny.UI.UISwitch(); this.uiTableLayoutPanel1.SuspendLayout(); this.SuspendLayout(); // @@ -58,6 +59,7 @@ namespace Sunny.UI.Demo // // uiTitlePanel2 // + this.uiTitlePanel2.CollapseDirection = UITitlePanel.TitlePosition.Top; this.uiTitlePanel2.Font = new System.Drawing.Font("宋体", 12F); this.uiTitlePanel2.Location = new System.Drawing.Point(331, 285); this.uiTitlePanel2.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); @@ -88,6 +90,7 @@ namespace Sunny.UI.Demo // // uiTitlePanel1 // + this.uiTitlePanel1.CollapseDirection = UITitlePanel.TitlePosition.Top; this.uiTitlePanel1.Font = new System.Drawing.Font("宋体", 12F); this.uiTitlePanel1.Location = new System.Drawing.Point(30, 285); this.uiTitlePanel1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); @@ -201,11 +204,26 @@ namespace Sunny.UI.Demo this.uiLine2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; this.uiLine2.ZoomScaleRect = new System.Drawing.Rectangle(0, 0, 0, 0); // + // uiSwitch1 + // + this.uiSwitch1.Active = true; + this.uiSwitch1.ActiveText = "Top"; + this.uiSwitch1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.uiSwitch1.InActiveText = "Bottom"; + this.uiSwitch1.Location = new System.Drawing.Point(625, 285); + this.uiSwitch1.MinimumSize = new System.Drawing.Size(1, 1); + this.uiSwitch1.Name = "uiSwitch1"; + this.uiSwitch1.Size = new System.Drawing.Size(85, 29); + this.uiSwitch1.TabIndex = 80; + this.uiSwitch1.Text = "uiSwitch1"; + this.uiSwitch1.ValueChanged += new Sunny.UI.UISwitch.OnValueChanged(this.uiSwitch1_ValueChanged); + // // FPanel // this.AllowShowTitle = true; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; this.ClientSize = new System.Drawing.Size(800, 662); + this.Controls.Add(this.uiSwitch1); this.Controls.Add(this.uiLine2); this.Controls.Add(this.uiLine1); this.Controls.Add(this.uiTableLayoutPanel1); @@ -236,5 +254,6 @@ namespace Sunny.UI.Demo private UILine uiLine2; private UIButton uiButton4; private UIButton uiButton3; + private UISwitch uiSwitch1; } } \ No newline at end of file diff --git a/SunnyUI.Demo/Controls/FPanel.cs b/SunnyUI.Demo/Controls/FPanel.cs index 5440ee88..2d270fe6 100644 --- a/SunnyUI.Demo/Controls/FPanel.cs +++ b/SunnyUI.Demo/Controls/FPanel.cs @@ -6,5 +6,10 @@ { InitializeComponent(); } + + private void uiSwitch1_ValueChanged(object sender, bool value) + { + uiTitlePanel2.CollapseDirection = value ? UITitlePanel.TitlePosition.Top : UITitlePanel.TitlePosition.Bottom; + } } } -- Gitee From ff2f0e055ee557784db6750b5809dfdb79ebab63 Mon Sep 17 00:00:00 2001 From: chenren Date: Tue, 17 Oct 2023 14:09:34 +0800 Subject: [PATCH 3/4] =?UTF-8?q?UITitlePanel=E4=BF=AE=E6=AD=A3=E7=AE=AD?= =?UTF-8?q?=E5=A4=B4=E6=96=B9=E5=90=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SunnyUI/Controls/UITitlePanel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SunnyUI/Controls/UITitlePanel.cs b/SunnyUI/Controls/UITitlePanel.cs index b9b51922..fe708407 100644 --- a/SunnyUI/Controls/UITitlePanel.cs +++ b/SunnyUI/Controls/UITitlePanel.cs @@ -177,7 +177,7 @@ namespace Sunny.UI g.FillRectangle(UIStyles.ActiveStyleColor.ButtonFillHoverColor, ControlBoxRect); } - g.DrawFontImage(Collapsed ^ titleAtTop ? 61703 : 61702, 24, SymbolColor, + g.DrawFontImage(Collapsed ^ !titleAtTop ? 61703 : 61702, 24, SymbolColor, new Rectangle(ControlBoxRect.Left + 2, ControlBoxRect.Top, ControlBoxRect.Width, ControlBoxRect.Height)); } -- Gitee From a5b6ee058649d733f8ac7f28c9e51fed7e03b41a Mon Sep 17 00:00:00 2001 From: asuper Date: Tue, 17 Oct 2023 14:48:43 +0800 Subject: [PATCH 4/4] =?UTF-8?q?UITitlePanel=E6=94=B6=E7=BC=A9=E6=97=B6?= =?UTF-8?q?=E9=9A=90=E8=97=8F=E5=AD=90=E6=8E=A7=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SunnyUI/Controls/UITitlePanel.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/SunnyUI/Controls/UITitlePanel.cs b/SunnyUI/Controls/UITitlePanel.cs index fe708407..897a1d65 100644 --- a/SunnyUI/Controls/UITitlePanel.cs +++ b/SunnyUI/Controls/UITitlePanel.cs @@ -402,6 +402,10 @@ namespace Sunny.UI if (CollapseDirection == TitlePosition.Bottom) { Top += Height - TitleHeight; + foreach (Control control in Controls) + { + control.Top += TitleHeight; + } } Height = TitleHeight; } @@ -412,6 +416,10 @@ namespace Sunny.UI if (CollapseDirection == TitlePosition.Bottom) { Top -= Height - TitleHeight; + foreach (Control control in Controls) + { + control.Top -= TitleHeight; + } } } -- Gitee