From 8295a99e2b094a9ef54fcafcb2eb34d6a1e605fe Mon Sep 17 00:00:00 2001 From: Sunny Date: Mon, 28 Aug 2023 15:19:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=85=A8=E5=B1=80=E7=9F=A9?= =?UTF-8?q?=E5=BD=A2=E8=AE=BE=E8=AE=A1=EF=BC=8C=E5=BF=BD=E7=95=A5=E5=9C=86?= =?UTF-8?q?=E8=A7=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SunnyUI/Common/UGDI.cs | 18 +++++++++++++++--- SunnyUI/Common/UGraphics.cs | 8 ++++---- SunnyUI/Controls/DropItem/UIDropControl.cs | 19 +++---------------- SunnyUI/Controls/UIGroupBox.cs | 5 +++-- SunnyUI/Controls/UISwitch.cs | 3 ++- SunnyUI/Controls/UITextBox.cs | 19 +++---------------- SunnyUI/Forms/UIForm.cs | 2 +- SunnyUI/Style/UIStyleManager.cs | 8 ++++++++ SunnyUI/Style/UIStyles.cs | 4 +++- 9 files changed, 42 insertions(+), 44 deletions(-) diff --git a/SunnyUI/Common/UGDI.cs b/SunnyUI/Common/UGDI.cs index ba8d8dee..dc40ec9d 100644 --- a/SunnyUI/Common/UGDI.cs +++ b/SunnyUI/Common/UGDI.cs @@ -312,7 +312,7 @@ namespace Sunny.UI { GraphicsPath path; - if (radiusSides == UICornerRadiusSides.None || radius == 0) + if (UIStyles.GlobalRectangle || radiusSides == UICornerRadiusSides.None || radius == 0) { path = new GraphicsPath(); path.AddLine(new Point(rect.X, rect.Y), new Point(rect.X, rect.Y + rect.Height)); @@ -341,7 +341,7 @@ namespace Sunny.UI { GraphicsPath path = new GraphicsPath(); - if ((!cornerLeftTop && !cornerRightTop && !cornerRightBottom && !cornerLeftBottom) || radius <= 0) + if (UIStyles.GlobalRectangle || (!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)); @@ -473,7 +473,7 @@ namespace Sunny.UI { GraphicsPath path = new GraphicsPath(); - if ((!cornerLeftTop && !cornerRightTop && !cornerRightBottom && !cornerLeftBottom) || radius <= 0) + if (UIStyles.GlobalRectangle || (!cornerLeftTop && !cornerRightTop && !cornerRightBottom && !cornerLeftBottom) || radius <= 0) { path = rect.GraphicsPath(); } @@ -507,6 +507,18 @@ namespace Sunny.UI return path; } + public static GraphicsPath CreateTrueRoundedRectanglePath(this Rectangle rect, int radius, int lineSize = 1) + { + GraphicsPath path = new GraphicsPath(); + radius *= lineSize; + path.AddArc(rect.X, rect.Y, radius, radius, 180, 90); + path.AddArc(rect.X + rect.Width - radius, rect.Y, radius, radius, 270, 90); + path.AddArc(rect.X + rect.Width - radius, rect.Y + rect.Height - radius, radius, radius, 0, 90); + path.AddArc(rect.X, rect.Bottom - radius, radius, radius, 90, 90); + path.CloseFigure(); + return path; + } + /// /// 设置GDI高质量模式抗锯齿 /// diff --git a/SunnyUI/Common/UGraphics.cs b/SunnyUI/Common/UGraphics.cs index f21c9fee..8991eec8 100644 --- a/SunnyUI/Common/UGraphics.cs +++ b/SunnyUI/Common/UGraphics.cs @@ -1135,7 +1135,7 @@ namespace Sunny.UI public static void DrawRoundRectangle(this Graphics g, Pen pen, Rectangle rect, int cornerRadius, bool smooth = true) { g.Smooth(smooth); - if (cornerRadius > 0) + if (!UIStyles.GlobalRectangle && cornerRadius > 0) { using GraphicsPath path = rect.CreateRoundedRectanglePath(cornerRadius); g.DrawPath(pen, path); @@ -1159,7 +1159,7 @@ namespace Sunny.UI public static void FillRoundRectangle(this Graphics g, Brush brush, Rectangle rect, int cornerRadius, bool smooth = true) { g.Smooth(smooth); - if (cornerRadius > 0) + if (!UIStyles.GlobalRectangle && cornerRadius > 0) { using GraphicsPath path = rect.CreateRoundedRectanglePath(cornerRadius); g.FillPath(brush, path); @@ -1215,7 +1215,7 @@ namespace Sunny.UI /// 笔宽 public static void DrawRoundRectangle(this Graphics g, Color color, Rectangle rect, int cornerRadius, bool smooth = true, float penWidth = 1) { - if (cornerRadius > 0) + if (!UIStyles.GlobalRectangle && cornerRadius > 0) { using GraphicsPath path = rect.CreateRoundedRectanglePath(cornerRadius); g.DrawPath(color, path, smooth, penWidth); @@ -1236,7 +1236,7 @@ namespace Sunny.UI /// 平滑 public static void FillRoundRectangle(this Graphics g, Color color, Rectangle rect, int cornerRadius, bool smooth = true) { - if (cornerRadius > 0) + if (!UIStyles.GlobalRectangle && cornerRadius > 0) { using GraphicsPath path = rect.CreateRoundedRectanglePath(cornerRadius); g.FillPath(color, path, smooth); diff --git a/SunnyUI/Controls/DropItem/UIDropControl.cs b/SunnyUI/Controls/DropItem/UIDropControl.cs index 2ec74040..3d57a963 100644 --- a/SunnyUI/Controls/DropItem/UIDropControl.cs +++ b/SunnyUI/Controls/DropItem/UIDropControl.cs @@ -96,27 +96,14 @@ namespace Sunny.UI { tipsBtn = new UIButton(); tipsBtn.Cursor = System.Windows.Forms.Cursors.Hand; - tipsBtn.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(80)))), ((int)(((byte)(80))))); - tipsBtn.FillColor2 = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(80)))), ((int)(((byte)(80))))); - tipsBtn.FillHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(80)))), ((int)(((byte)(80))))); - tipsBtn.FillPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(80)))), ((int)(((byte)(80))))); - tipsBtn.FillSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(80)))), ((int)(((byte)(80))))); - tipsBtn.Location = new System.Drawing.Point(285, 519); - tipsBtn.MinimumSize = new System.Drawing.Size(1, 1); - tipsBtn.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(80)))), ((int)(((byte)(80))))); - tipsBtn.RectHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(80)))), ((int)(((byte)(80))))); - tipsBtn.RectPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(80)))), ((int)(((byte)(80))))); - tipsBtn.RectSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(80)))), ((int)(((byte)(80))))); - tipsBtn.Size = new System.Drawing.Size(9, 9); + tipsBtn.Size = new System.Drawing.Size(6, 6); tipsBtn.Style = Sunny.UI.UIStyle.Red; tipsBtn.StyleCustomMode = true; - tipsBtn.TabIndex = 118; - tipsBtn.ZoomScaleRect = new System.Drawing.Rectangle(0, 0, 0, 0); tipsBtn.Text = ""; tipsBtn.Click += TipsBtn_Click; Controls.Add(tipsBtn); - tipsBtn.Location = new System.Drawing.Point(Width - 11, 2); + tipsBtn.Location = new System.Drawing.Point(Width - 8, 2); tipsBtn.BringToFront(); } @@ -376,7 +363,7 @@ namespace Sunny.UI if (tipsBtn != null) { - tipsBtn.Location = new System.Drawing.Point(Width - 11, 2); + tipsBtn.Location = new System.Drawing.Point(Width - 8, 2); } } diff --git a/SunnyUI/Controls/UIGroupBox.cs b/SunnyUI/Controls/UIGroupBox.cs index 0e89c291..5ae9262d 100644 --- a/SunnyUI/Controls/UIGroupBox.cs +++ b/SunnyUI/Controls/UIGroupBox.cs @@ -38,6 +38,7 @@ namespace Sunny.UI public UIGroupBox() { InitializeComponent(); + TextAlignment = ContentAlignment.MiddleLeft; TextAlignmentChange += UIGroupBox_TextAlignmentChange; SetStyleFlags(true, false); } @@ -109,7 +110,7 @@ namespace Sunny.UI if (RectSides.GetValue(ToolStripStatusLabelBorderSides.Top)) { - if (RadiusSides.GetValue(UICornerRadiusSides.LeftTop)) + if (RadiusSides.GetValue(UICornerRadiusSides.LeftTop) && !UIStyles.GlobalRectangle) { g.DrawLine(RectColor, Radius / 2 * RectSize, TitleTop, textLeft, TitleTop, true, RectSize); } @@ -118,7 +119,7 @@ namespace Sunny.UI g.DrawLine(RectColor, 0, TitleTop, textLeft, TitleTop, true, RectSize); } - if (RadiusSides.GetValue(UICornerRadiusSides.RightTop)) + if (RadiusSides.GetValue(UICornerRadiusSides.RightTop) && !UIStyles.GlobalRectangle) { g.DrawLine(RectColor, textLeft + size.Width, TitleTop, Width - Radius / 2 * RectSize, TitleTop, true, RectSize); } diff --git a/SunnyUI/Controls/UISwitch.cs b/SunnyUI/Controls/UISwitch.cs index 97eab43d..44fdaed0 100644 --- a/SunnyUI/Controls/UISwitch.cs +++ b/SunnyUI/Controls/UISwitch.cs @@ -265,7 +265,8 @@ namespace Sunny.UI if (SwitchShape == UISwitchShape.Round) { Rectangle rect = new Rectangle(0, 0, Width - 1, Height - 1); - g.FillRoundRectangle(color, rect, rect.Height); + using GraphicsPath path1 = rect.CreateTrueRoundedRectanglePath(rect.Height); + g.FillPath(color, path1, true); int width = Width - 3 - 1 - 3 - (rect.Height - 6); if (!Active) diff --git a/SunnyUI/Controls/UITextBox.cs b/SunnyUI/Controls/UITextBox.cs index f0e0fae5..c5d65687 100644 --- a/SunnyUI/Controls/UITextBox.cs +++ b/SunnyUI/Controls/UITextBox.cs @@ -153,27 +153,14 @@ namespace Sunny.UI { tipsBtn = new UIButton(); tipsBtn.Cursor = System.Windows.Forms.Cursors.Hand; - tipsBtn.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(80)))), ((int)(((byte)(80))))); - tipsBtn.FillColor2 = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(80)))), ((int)(((byte)(80))))); - tipsBtn.FillHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(80)))), ((int)(((byte)(80))))); - tipsBtn.FillPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(80)))), ((int)(((byte)(80))))); - tipsBtn.FillSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(80)))), ((int)(((byte)(80))))); - tipsBtn.Location = new System.Drawing.Point(285, 519); - tipsBtn.MinimumSize = new System.Drawing.Size(1, 1); - tipsBtn.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(80)))), ((int)(((byte)(80))))); - tipsBtn.RectHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(80)))), ((int)(((byte)(80))))); - tipsBtn.RectPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(80)))), ((int)(((byte)(80))))); - tipsBtn.RectSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(80)))), ((int)(((byte)(80))))); - tipsBtn.Size = new System.Drawing.Size(9, 9); + tipsBtn.Size = new System.Drawing.Size(6, 6); tipsBtn.Style = Sunny.UI.UIStyle.Red; tipsBtn.StyleCustomMode = true; - tipsBtn.TabIndex = 118; - tipsBtn.ZoomScaleRect = new System.Drawing.Rectangle(0, 0, 0, 0); tipsBtn.Text = ""; tipsBtn.Click += TipsBtn_Click; Controls.Add(tipsBtn); - tipsBtn.Location = new System.Drawing.Point(Width - 11, 2); + tipsBtn.Location = new System.Drawing.Point(Width - 8, 2); tipsBtn.BringToFront(); } @@ -680,7 +667,7 @@ namespace Sunny.UI if (tipsBtn != null) { - tipsBtn.Location = new System.Drawing.Point(Width - 11, 2); + tipsBtn.Location = new System.Drawing.Point(Width - 8, 2); } } diff --git a/SunnyUI/Forms/UIForm.cs b/SunnyUI/Forms/UIForm.cs index 27b5f7ed..15b24833 100644 --- a/SunnyUI/Forms/UIForm.cs +++ b/SunnyUI/Forms/UIForm.cs @@ -1638,7 +1638,7 @@ namespace Sunny.UI return; } - if (WindowState == FormWindowState.Maximized) + if (WindowState == FormWindowState.Maximized || UIStyles.GlobalRectangle) { FormEx.SetFormRoundRectRegion(this, 0); } diff --git a/SunnyUI/Style/UIStyleManager.cs b/SunnyUI/Style/UIStyleManager.cs index 9e560f82..b6ecd869 100644 --- a/SunnyUI/Style/UIStyleManager.cs +++ b/SunnyUI/Style/UIStyleManager.cs @@ -105,6 +105,14 @@ namespace Sunny.UI set => UIStyles.GlobalFont = value; } + [DefaultValue(false)] + [Description("全局矩形设置,开启后所有控件都关闭圆角效果"), Category("SunnyUI")] + public bool GlobalRectangle + { + get => UIStyles.GlobalRectangle; + set => UIStyles.GlobalRectangle = value; + } + /// /// 版本 /// diff --git a/SunnyUI/Style/UIStyles.cs b/SunnyUI/Style/UIStyles.cs index 52c759ae..070bc801 100644 --- a/SunnyUI/Style/UIStyles.cs +++ b/SunnyUI/Style/UIStyles.cs @@ -41,6 +41,8 @@ namespace Sunny.UI { public static bool GlobalFont { get; set; } = false; + public static bool GlobalRectangle { get; set; } = false; + public static bool DPIScale { get; set; } public static bool ZoomScale { get; set; } @@ -115,7 +117,7 @@ namespace Sunny.UI internal static Font Font() { byte gdiCharSet = GetGdiCharSet("微软雅黑"); - return new Font("微软雅黑", DefaultFontSize, FontStyle.Regular, GraphicsUnit.Point, gdiCharSet); + return new Font(familyName: "微软雅黑", DefaultFontSize, FontStyle.Regular, GraphicsUnit.Point, gdiCharSet); } ///