* UIForm2: 修改属性与UIForm兼容

This commit is contained in:
Sunny 2024-07-21 21:20:58 +08:00
parent 35ad7bc7a5
commit bdaf058240
3 changed files with 72 additions and 3 deletions

View File

@ -185,7 +185,7 @@ namespace Sunny.UI
} }
} }
public static class FontAweSomeV6ItemBuilder internal static class FontAweSomeV6ItemBuilder
{ {
public static void Build() public static void Build()
{ {

View File

@ -107,6 +107,8 @@ namespace Sunny.UI
ZoomScaleRectChanged?.Invoke(this, ZoomScaleRect); ZoomScaleRectChanged?.Invoke(this, ZoomScaleRect);
} }
public event OnZoomScaleRectChanged ZoomScaleRectChanged;
[DefaultValue(typeof(Size), "0, 0")] [DefaultValue(typeof(Size), "0, 0")]
[Description("设计界面大小"), Category("SunnyUI")] [Description("设计界面大小"), Category("SunnyUI")]
public Size ZoomScaleSize public Size ZoomScaleSize
@ -761,8 +763,6 @@ namespace Sunny.UI
SetZoomScaleRect(); SetZoomScaleRect();
} }
public event OnZoomScaleRectChanged ZoomScaleRectChanged;
/// <summary> /// <summary>
/// 是否显示圆角 /// 是否显示圆角
/// </summary> /// </summary>

View File

@ -23,6 +23,7 @@
* 2024-05-16: V3.6.6 Resizable替代ShowDragStretch * 2024-05-16: V3.6.6 Resizable替代ShowDragStretch
* 2024-06-08: V3.6.6 * 2024-06-08: V3.6.6
* 2024-07-20: V3.6.8 * 2024-07-20: V3.6.8
* 2024-07-21: V3.6.8 UIForm兼容
******************************************************************************/ ******************************************************************************/
using System; 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); fieldH = typeof(Control).GetField("_clientHeight", BindingFlags.NonPublic | BindingFlags.Instance) ?? typeof(Control).GetField("clientHeight", BindingFlags.NonPublic | BindingFlags.Instance);
} }
/// <summary>
/// 禁止控件跟随窗体缩放
/// </summary>
[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;
}
/// <summary>
/// 控件缩放前在其容器里的位置
/// </summary>
[Browsable(false), DefaultValue(typeof(Rectangle), "0, 0, 0, 0")]
public Rectangle ZoomScaleRect { get; set; }
/// <summary>
/// 设置控件缩放比例
/// </summary>
/// <param name="scale">缩放比例</param>
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)] [Description("显示边框可拖拽调整窗体大小"), Category("SunnyUI"), DefaultValue(false)]
public bool Resizable public bool Resizable
{ {