增加全局矩形设计,忽略圆角

This commit is contained in:
Sunny 2023-08-28 15:19:29 +08:00
parent 01e292b111
commit 8295a99e2b
9 changed files with 42 additions and 44 deletions

View File

@ -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;
}
/// <summary>
/// 设置GDI高质量模式抗锯齿
/// </summary>

View File

@ -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
/// <param name="penWidth">笔宽</param>
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
/// <param name="smooth">平滑</param>
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);

View File

@ -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);
}
}

View File

@ -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);
}

View File

@ -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)

View File

@ -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);
}
}

View File

@ -1638,7 +1638,7 @@ namespace Sunny.UI
return;
}
if (WindowState == FormWindowState.Maximized)
if (WindowState == FormWindowState.Maximized || UIStyles.GlobalRectangle)
{
FormEx.SetFormRoundRectRegion(this, 0);
}

View File

@ -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;
}
/// <summary>
/// 版本
/// </summary>

View File

@ -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);
}
/// <summary>