重构窗体缩放

This commit is contained in:
Sunny 2022-04-11 17:06:11 +08:00
parent b50a56da5a
commit 57c83b2b1b
9 changed files with 47 additions and 12 deletions

View File

@ -74,12 +74,12 @@ namespace Sunny.UI
return ctrl as Form; return ctrl as Form;
} }
public static Control SettingToCenter(this Control ctrl) public static Control SetToTheCenterOfParent(this Control ctrl)
{ {
return ctrl.SettingToXCenter().SettingToYCenter(); return ctrl.SetToTheHorizontalCenterOfParent().SetToTheVerticalCenterOfParent();
} }
public static Control SettingToXCenter(this Control ctrl) public static Control SetToTheHorizontalCenterOfParent(this Control ctrl)
{ {
if (ctrl != null && ctrl.Parent != null) if (ctrl != null && ctrl.Parent != null)
ctrl.Left = (ctrl.Parent.Width - ctrl.Width) / 2; ctrl.Left = (ctrl.Parent.Width - ctrl.Width) / 2;
@ -87,7 +87,7 @@ namespace Sunny.UI
return ctrl; return ctrl;
} }
public static Control SettingToYCenter(this Control ctrl) public static Control SetToTheVerticalCenterOfParent(this Control ctrl)
{ {
if (ctrl != null && ctrl.Parent != null) if (ctrl != null && ctrl.Parent != null)
ctrl.Top = (ctrl.Parent.Height - ctrl.Height) / 2; ctrl.Top = (ctrl.Parent.Height - ctrl.Height) / 2;

View File

@ -57,7 +57,7 @@ namespace Sunny.UI
public virtual void SetZoomScale(float scale) public virtual void SetZoomScale(float scale)
{ {
radius = UIZoomScale.Calc(baseRadius, scale);
} }
protected bool selected; protected bool selected;
@ -167,6 +167,7 @@ namespace Sunny.UI
} }
private int radius = 5; private int radius = 5;
private int baseRadius = 5;
/// <summary> /// <summary>
/// 圆角角度 /// 圆角角度
@ -180,7 +181,7 @@ namespace Sunny.UI
{ {
if (radius != value) if (radius != value)
{ {
radius = Math.Max(0, value); baseRadius = radius = Math.Max(0, value);
Invalidate(); Invalidate();
} }
} }

View File

@ -67,6 +67,12 @@ namespace Sunny.UI
rectDisableColor = UIStyles.Blue.RectDisableColor; rectDisableColor = UIStyles.Blue.RectDisableColor;
} }
public override void SetZoomScale(float scale)
{
base.SetZoomScale(scale);
circleSize = UIZoomScale.Calc(baseCircleSize, scale);
}
private bool showTips = false; private bool showTips = false;
[Description("是否显示角标"), Category("SunnyUI")] [Description("是否显示角标"), Category("SunnyUI")]
@ -435,6 +441,7 @@ namespace Sunny.UI
} }
private int circleSize = 50; private int circleSize = 50;
private int baseCircleSize = 50;
[DefaultValue(50)] [DefaultValue(50)]
[Description("字体图标背景大小"), Category("SunnyUI")] [Description("字体图标背景大小"), Category("SunnyUI")]
@ -443,7 +450,7 @@ namespace Sunny.UI
get => circleSize; get => circleSize;
set set
{ {
circleSize = value; baseCircleSize = circleSize = value;
Invalidate(); Invalidate();
} }
} }

View File

@ -34,7 +34,7 @@ namespace Sunny.UI
/// provide a sleek looking representation of an LED light that is sizable, /// provide a sleek looking representation of an LED light that is sizable,
/// has a transparent background and can be set to different colors. /// has a transparent background and can be set to different colors.
/// </summary> /// </summary>
public class UILedBulb : Control public class UILedBulb : Control, IZoomScale
{ {
#region Public and Private Members #region Public and Private Members
@ -44,6 +44,17 @@ namespace Sunny.UI
private readonly Color[] _surroundColor = new Color[] { Color.FromArgb(0, 255, 255, 255) }; private readonly Color[] _surroundColor = new Color[] { Color.FromArgb(0, 255, 255, 255) };
private readonly Timer timer; private readonly Timer timer;
[DefaultValue(false), Category("SunnyUI"), Description("禁止控件跟随窗体缩放")]
public bool ZoomScaleDisabled { get; set; }
[Browsable(false)]
public Rectangle ZoomScaleRect { get; set; }
public void SetZoomScale(float scale)
{
}
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
base.Dispose(disposing); base.Dispose(disposing);

View File

@ -78,6 +78,7 @@ namespace Sunny.UI
Bar.ForeColor = Color.Silver; Bar.ForeColor = Color.Silver;
Bar.HoverColor = Color.Silver; Bar.HoverColor = Color.Silver;
Bar.PressColor = Color.Silver; Bar.PressColor = Color.Silver;
Bar.ZoomScaleDisabled = true;
Controls.Add(Bar); Controls.Add(Bar);
Version = UIGlobal.Version; Version = UIGlobal.Version;

View File

@ -41,6 +41,7 @@ namespace Sunny.UI
Style = UIStyle.Custom; Style = UIStyle.Custom;
Width = 200; Width = 200;
Height = 16; Height = 16;
ZoomScaleDisabled = true;
} }
private ConcurrentDictionary<UIPipe, Bitmap> linked = new ConcurrentDictionary<UIPipe, Bitmap>(); private ConcurrentDictionary<UIPipe, Bitmap> linked = new ConcurrentDictionary<UIPipe, Bitmap>();

View File

@ -46,6 +46,8 @@ namespace Sunny.UI
l1.ItemsCountChange += L1_ItemsCountChange; l1.ItemsCountChange += L1_ItemsCountChange;
l2.ItemsCountChange += L2_ItemsCountChange; l2.ItemsCountChange += L2_ItemsCountChange;
l1.ZoomScaleDisabled = l2.ZoomScaleDisabled = true;
b1.ZoomScaleDisabled = b2.ZoomScaleDisabled = b3.ZoomScaleDisabled = b4.ZoomScaleDisabled = true;
} }
[DefaultValue(true)] [DefaultValue(true)]

View File

@ -31,7 +31,7 @@ namespace Sunny.UI
[ToolboxItem(true)] [ToolboxItem(true)]
[DefaultProperty("Active")] [DefaultProperty("Active")]
[DefaultEvent("ActiveChanged")] [DefaultEvent("ActiveChanged")]
public class UIValve : Control public sealed class UIValve : Control, IZoomScale
{ {
public UIValve() public UIValve()
{ {
@ -41,6 +41,18 @@ namespace Sunny.UI
fillColor = Color.White; fillColor = Color.White;
valveColor = UIColor.Blue; valveColor = UIColor.Blue;
Version = UIGlobal.Version; Version = UIGlobal.Version;
ZoomScaleDisabled = true;
}
[DefaultValue(false), Category("SunnyUI"), Description("禁止控件跟随窗体缩放")]
public bool ZoomScaleDisabled { get; set; }
[Browsable(false)]
public Rectangle ZoomScaleRect { get; set; }
public void SetZoomScale(float scale)
{
} }
protected override void OnClick(EventArgs e) protected override void OnClick(EventArgs e)

View File

@ -12,7 +12,7 @@ namespace Sunny.UI
bool ZoomScaleDisabled { get; set; } bool ZoomScaleDisabled { get; set; }
} }
internal static class UIZoomScale public static class UIZoomScale
{ {
public static Rectangle Create(Control control) public static Rectangle Create(Control control)
{ {
@ -60,12 +60,12 @@ namespace Sunny.UI
} }
} }
internal static int Calc(int size, float scale) public static int Calc(int size, float scale)
{ {
return (int)(size * scale + 0.5); return (int)(size * scale + 0.5);
} }
internal static Size Calc(Size size, float scale) public static Size Calc(Size size, float scale)
{ {
return new Size(Calc(size.Width, scale), Calc(size.Height, scale)); return new Size(Calc(size.Width, scale), Calc(size.Height, scale));
} }