From bdaf058240c1f8c1598798c0b720f597d48cbeac Mon Sep 17 00:00:00 2001 From: Sunny Date: Sun, 21 Jul 2024 21:20:58 +0800 Subject: [PATCH] =?UTF-8?q?*=20UIForm2:=20=E4=BF=AE=E6=94=B9=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E4=B8=8EUIForm=E5=85=BC=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SunnyUI/Font/UFontImages.cs | 2 +- SunnyUI/Forms/UIForm.cs | 4 +-- SunnyUI/Forms/UIForm2.cs | 69 +++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 3 deletions(-) diff --git a/SunnyUI/Font/UFontImages.cs b/SunnyUI/Font/UFontImages.cs index 1690ff9e..2b165d7d 100644 --- a/SunnyUI/Font/UFontImages.cs +++ b/SunnyUI/Font/UFontImages.cs @@ -185,7 +185,7 @@ namespace Sunny.UI } } - public static class FontAweSomeV6ItemBuilder + internal static class FontAweSomeV6ItemBuilder { public static void Build() { diff --git a/SunnyUI/Forms/UIForm.cs b/SunnyUI/Forms/UIForm.cs index 427b822d..5ae71239 100644 --- a/SunnyUI/Forms/UIForm.cs +++ b/SunnyUI/Forms/UIForm.cs @@ -107,6 +107,8 @@ namespace Sunny.UI ZoomScaleRectChanged?.Invoke(this, ZoomScaleRect); } + public event OnZoomScaleRectChanged ZoomScaleRectChanged; + [DefaultValue(typeof(Size), "0, 0")] [Description("设计界面大小"), Category("SunnyUI")] public Size ZoomScaleSize @@ -761,8 +763,6 @@ namespace Sunny.UI SetZoomScaleRect(); } - public event OnZoomScaleRectChanged ZoomScaleRectChanged; - /// /// 是否显示圆角 /// diff --git a/SunnyUI/Forms/UIForm2.cs b/SunnyUI/Forms/UIForm2.cs index 84282759..166b8a7c 100644 --- a/SunnyUI/Forms/UIForm2.cs +++ b/SunnyUI/Forms/UIForm2.cs @@ -23,6 +23,7 @@ * 2024-05-16: V3.6.6 Resizable替代ShowDragStretch,显示边框可拖拽调整窗体大小 * 2024-06-08: V3.6.6 防止图标转换错误 * 2024-07-20: V3.6.8 修改最大化时按钮位置 + * 2024-07-21: V3.6.8 修改属性与UIForm兼容 ******************************************************************************/ using System; @@ -48,6 +49,74 @@ namespace Sunny.UI fieldH = typeof(Control).GetField("_clientHeight", BindingFlags.NonPublic | BindingFlags.Instance) ?? typeof(Control).GetField("clientHeight", BindingFlags.NonPublic | BindingFlags.Instance); } + /// + /// 禁止控件跟随窗体缩放 + /// + [DefaultValue(false), Category("SunnyUI"), Description("禁止控件跟随窗体缩放")] + public bool ZoomScaleDisabled { get; set; } + + private void SetZoomScaleRect() + { + if (ZoomScaleRect.Width == 0 && ZoomScaleRect.Height == 0) + { + ZoomScaleRect = new Rectangle(ZoomScaleSize.Width, ZoomScaleSize.Height, 0, 0); + } + + if (ZoomScaleRect.Width == 0 && ZoomScaleRect.Height == 0) + { + ZoomScaleRect = new Rectangle(Left, Top, Width, Height); + } + + ZoomScaleRectChanged?.Invoke(this, ZoomScaleRect); + } + + public event OnZoomScaleRectChanged ZoomScaleRectChanged; + + [DefaultValue(typeof(Size), "0, 0")] + [Description("设计界面大小"), Category("SunnyUI")] + public Size ZoomScaleSize + { + get; + set; + } + + /// + /// 控件缩放前在其容器里的位置 + /// + [Browsable(false), DefaultValue(typeof(Rectangle), "0, 0, 0, 0")] + public Rectangle ZoomScaleRect { get; set; } + + /// + /// 设置控件缩放比例 + /// + /// 缩放比例 + private void SetZoomScale() + { + if (ZoomScaleDisabled) return; + if (!UIStyles.DPIScale || !UIStyles.ZoomScale) return; + if (ZoomScaleRect.Width == 0 || ZoomScaleRect.Height == 0) return; + if (Width == 0 || Height == 0) return; + float scale = Math.Min(Width * 1.0f / ZoomScaleRect.Width, Height * 1.0f / ZoomScaleRect.Height); + if (scale.EqualsFloat(0)) return; + foreach (Control control in this.GetAllZoomScaleControls()) + { + if (control is IZoomScale ctrl) + { + UIZoomScale.SetZoomScale(control, scale); + } + } + + ZoomScaleChanged?.Invoke(this, scale); + } + + public event OnZoomScaleChanged ZoomScaleChanged; + + protected override void OnShown(EventArgs e) + { + base.OnShown(e); + SetZoomScaleRect(); + } + [Description("显示边框可拖拽调整窗体大小"), Category("SunnyUI"), DefaultValue(false)] public bool Resizable {