From 572b2601c0011e7a4451e45355e562dfbe8a7c35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E6=B2=9B=20=E7=8E=8B?= <1016423262@qq.com> Date: Sat, 28 Jun 2025 14:44:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=8E=A7=E4=BB=B6?= =?UTF-8?q?=E5=9C=A8=E9=87=8D=E7=BB=98=E5=87=BD=E6=95=B0=E4=B8=AD=E4=BF=AE?= =?UTF-8?q?=E6=94=B9Region=E4=B8=8D=E6=96=AD=E9=87=8D=E7=BB=98=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .../HZH_Controls/Controls/UCControlBase.cs | 63 +++++++++++++------ 2 files changed, 46 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index e829eba..4d496a0 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ /HZH_Controls/Help /HZH_Controls/HZH_Controls.sln.GhostDoc.xml /HZH_Controls/.vs/ +/.vs/hzh_control/v17 diff --git a/HZH_Controls/HZH_Controls/Controls/UCControlBase.cs b/HZH_Controls/HZH_Controls/Controls/UCControlBase.cs index b9d84a9..02749b7 100644 --- a/HZH_Controls/HZH_Controls/Controls/UCControlBase.cs +++ b/HZH_Controls/HZH_Controls/Controls/UCControlBase.cs @@ -45,12 +45,19 @@ namespace HZH_Controls.Controls /// The corner radius /// private int _cornerRadius = 24; - - /// - /// The is show rect + /// 标记上一次修改Region的时候bounds,防止不停重绘 /// - private bool _isShowRect = false; + private Rectangle bounds_reg; + /// + /// 标记上一次修改Region的时候radius,防止不停重绘 + /// + private int radius_reg; + + /// + /// The is show rect + /// + private bool _isShowRect = false; /// /// The rect color @@ -192,17 +199,20 @@ namespace HZH_Controls.Controls { if (this.Visible) { - if (this._isRadius) - { - this.SetWindowRegion(); - } - else + if (NeedSetRegion()) { - //关闭圆角后显示为原矩形 - GraphicsPath g = new GraphicsPath(); - g.AddRectangle(base.ClientRectangle); - g.CloseFigure(); - base.Region = new Region(g); + if (this._isRadius) + { + this.SetWindowRegion(); + } + else + { + //关闭圆角后显示为原矩形 + GraphicsPath g = new GraphicsPath(); + g.AddRectangle(base.ClientRectangle); + g.CloseFigure(); + base.Region = new Region(g); + } } GraphicsPath graphicsPath = new GraphicsPath(); @@ -235,10 +245,27 @@ namespace HZH_Controls.Controls base.OnPaint(e); } - /// - /// Sets the window region. - /// - private void SetWindowRegion() + private bool NeedSetRegion() + { + if (this.bounds_reg != this.Bounds) + { + this.bounds_reg = this.Bounds; + this.radius_reg = this.ConerRadius; + return true; + } + if (this.radius_reg != this.ConerRadius) + { + this.bounds_reg = this.Bounds; + this.radius_reg = this.ConerRadius; + return true; + } + return false; + } + + /// + /// Sets the window region. + /// + private void SetWindowRegion() { GraphicsPath path = new GraphicsPath(); Rectangle rect = new Rectangle(-1, -1, base.Width + 1, base.Height); -- Gitee