diff --git a/SunnyUI/Controls/Color/UIColorWheel.cs b/SunnyUI/Controls/Color/UIColorWheel.cs index 95a5bab0..aadc631a 100644 --- a/SunnyUI/Controls/Color/UIColorWheel.cs +++ b/SunnyUI/Controls/Color/UIColorWheel.cs @@ -8,7 +8,7 @@ using System.Windows.Forms; namespace Sunny.UI { [ToolboxItem(false)] - public sealed class UIColorWheel : Control, IStyleInterface + public sealed class UIColorWheel : Control, IStyleInterface, IZoomScale { public event EventHandler SelectedColorChanged; @@ -34,10 +34,15 @@ namespace Sunny.UI } [DefaultValue(false), Category("SunnyUI"), Description("禁止控件跟随窗体缩放")] - public bool ForbidControlScale { get; set; } + public bool ZoomScaleDisabled { get; set; } [Browsable(false)] - public ControlScaleInfo DesignedRect { get; private set; } + public Rectangle ZoomScaleRect { get; set; } + + public void SetZoomScale(float scale) + { + + } [Browsable(false)] public bool IsScaled { get; private set; } diff --git a/SunnyUI/Controls/Color/UILabelRotate.cs b/SunnyUI/Controls/Color/UILabelRotate.cs index 9cdfab33..4e00373e 100644 --- a/SunnyUI/Controls/Color/UILabelRotate.cs +++ b/SunnyUI/Controls/Color/UILabelRotate.cs @@ -5,17 +5,22 @@ using System.Windows.Forms; namespace Sunny.UI { [ToolboxItem(false)] - public class LabelRotate : Control, IStyleInterface + public class LabelRotate : Control, IStyleInterface, IZoomScale { private float m_textAngle = 0; private ContentAlignment m_rotatePointAlignment = ContentAlignment.MiddleCenter; private ContentAlignment m_textAlignment = ContentAlignment.MiddleLeft; - [Browsable(false)] - public ControlScaleInfo DesignedRect { get; private set; } - [DefaultValue(false), Category("SunnyUI"), Description("禁止控件跟随窗体缩放")] - public bool ForbidControlScale { get; set; } + public bool ZoomScaleDisabled { get; set; } + + [Browsable(false)] + public Rectangle ZoomScaleRect { get; set; } + + public virtual void SetZoomScale(float scale) + { + + } [Browsable(false)] public bool IsScaled { get; private set; } diff --git a/SunnyUI/Controls/UIAvatar.cs b/SunnyUI/Controls/UIAvatar.cs index e5eccdea..6199e814 100644 --- a/SunnyUI/Controls/UIAvatar.cs +++ b/SunnyUI/Controls/UIAvatar.cs @@ -35,7 +35,7 @@ namespace Sunny.UI [DefaultEvent("Click")] [DefaultProperty("Symbol")] [ToolboxItem(true)] - public sealed class UIAvatar : UIControl, ISymbol, IControlScale + public sealed class UIAvatar : UIControl, ISymbol, IZoomScale { /// /// 澶村儚鍥炬爣绫诲瀷 @@ -356,10 +356,11 @@ namespace Sunny.UI PaintAgain?.Invoke(this, e); } - public void SetControlScale(float scale) + public override void SetZoomScale(float scale) { - avatarSize = UIDPIScale.Calc(baseAvatorSize, scale); - symbolSize = UIDPIScale.Calc(baseSymbolSize, scale); + base.SetZoomScale(scale); + avatarSize = UIZoomScale.Calc(baseAvatorSize, scale); + symbolSize = UIZoomScale.Calc(baseSymbolSize, scale); Invalidate(); } } diff --git a/SunnyUI/Controls/UIContextMenuStrip.cs b/SunnyUI/Controls/UIContextMenuStrip.cs index 8c86d7fc..99fc5bda 100644 --- a/SunnyUI/Controls/UIContextMenuStrip.cs +++ b/SunnyUI/Controls/UIContextMenuStrip.cs @@ -27,7 +27,7 @@ using System.Windows.Forms; namespace Sunny.UI { - public sealed class UIContextMenuStrip : ContextMenuStrip, IStyleInterface + public sealed class UIContextMenuStrip : ContextMenuStrip, IStyleInterface, IZoomScale { public ContextMenuColorTable ColorTable = new ContextMenuColorTable(); @@ -43,10 +43,15 @@ namespace Sunny.UI } [DefaultValue(false), Category("SunnyUI"), Description("绂佹鎺т欢璺熼殢绐椾綋缂╂斁")] - public bool ForbidControlScale { get; set; } + public bool ZoomScaleDisabled { get; set; } [Browsable(false)] - public ControlScaleInfo DesignedRect { get; private set; } + public Rectangle ZoomScaleRect { get; set; } + + public void SetZoomScale(float scale) + { + + } [Browsable(false), DefaultValue(false)] public bool IsScaled { get; set; } diff --git a/SunnyUI/Controls/UIControl.cs b/SunnyUI/Controls/UIControl.cs index 43a4c68f..871f19bc 100644 --- a/SunnyUI/Controls/UIControl.cs +++ b/SunnyUI/Controls/UIControl.cs @@ -36,7 +36,7 @@ namespace Sunny.UI /// 鎺т欢鍩虹被 /// [ToolboxItem(false)] - public class UIControl : Control, IStyleInterface + public class UIControl : Control, IStyleInterface, IZoomScale { /// /// 鏋勯犲嚱鏁 @@ -49,25 +49,16 @@ namespace Sunny.UI base.MinimumSize = new Size(1, 1); } - [Browsable(false)] - public ControlScaleInfo DesignedRect { get; private set; } - - protected override void OnVisibleChanged(EventArgs e) - { - base.OnVisibleChanged(e); - SetDesignedSize(); - } - - protected virtual void SetDesignedSize() - { - if (DesignedRect.Width == 0 && DesignedRect.Height == 0) - { - DesignedRect = new ControlScaleInfo(this); - } - } - [DefaultValue(false), Category("SunnyUI"), Description("绂佹鎺т欢璺熼殢绐椾綋缂╂斁")] - public bool ForbidControlScale { get; set; } + public bool ZoomScaleDisabled { get; set; } + + [Browsable(false)] + public Rectangle ZoomScaleRect { get; set; } + + public virtual void SetZoomScale(float scale) + { + + } protected bool selected; diff --git a/SunnyUI/Controls/UIDataGridView.cs b/SunnyUI/Controls/UIDataGridView.cs index abbbae44..2a4a95e6 100644 --- a/SunnyUI/Controls/UIDataGridView.cs +++ b/SunnyUI/Controls/UIDataGridView.cs @@ -38,7 +38,7 @@ using System.Windows.Forms; namespace Sunny.UI { - public class UIDataGridView : DataGridView, IStyleInterface + public class UIDataGridView : DataGridView, IStyleInterface, IZoomScale { private readonly UIScrollBar VBar = new UIScrollBar(); private readonly UIHorScrollBarEx HBar = new UIHorScrollBarEx(); @@ -101,23 +101,14 @@ namespace Sunny.UI } [DefaultValue(false), Category("SunnyUI"), Description("绂佹鎺т欢璺熼殢绐椾綋缂╂斁")] - public bool ForbidControlScale { get; set; } + public bool ZoomScaleDisabled { get; set; } [Browsable(false)] - public ControlScaleInfo DesignedRect { get; private set; } + public Rectangle ZoomScaleRect { get; set; } - protected override void OnVisibleChanged(EventArgs e) + public virtual void SetZoomScale(float scale) { - base.OnVisibleChanged(e); - SetDesignedSize(); - } - protected virtual void SetDesignedSize() - { - if (DesignedRect.Width == 0 && DesignedRect.Height == 0) - { - DesignedRect = new ControlScaleInfo(this); - } } [Browsable(false)] diff --git a/SunnyUI/Controls/UIImageButton.cs b/SunnyUI/Controls/UIImageButton.cs index c601bd11..91ac03e8 100644 --- a/SunnyUI/Controls/UIImageButton.cs +++ b/SunnyUI/Controls/UIImageButton.cs @@ -30,7 +30,7 @@ namespace Sunny.UI /// /// 鍥惧儚鎸夐挳 /// - public sealed class UIImageButton : PictureBox, IStyleInterface + public sealed class UIImageButton : PictureBox, IStyleInterface, IZoomScale { private bool IsPress; private bool IsHover; @@ -44,24 +44,15 @@ namespace Sunny.UI private ContentAlignment textAlign = ContentAlignment.MiddleCenter; private Color foreColor = UIFontColor.Primary; - [Browsable(false)] - public ControlScaleInfo DesignedRect { get; private set; } - [DefaultValue(false), Category("SunnyUI"), Description("绂佹鎺т欢璺熼殢绐椾綋缂╂斁")] - public bool ForbidControlScale { get; set; } + public bool ZoomScaleDisabled { get; set; } - protected override void OnVisibleChanged(EventArgs e) - { - base.OnVisibleChanged(e); - SetDesignedSize(); - } + [Browsable(false)] + public Rectangle ZoomScaleRect { get; set; } - private void SetDesignedSize() + public void SetZoomScale(float scale) { - if (DesignedRect.Width == 0 && DesignedRect.Height == 0) - { - DesignedRect = new ControlScaleInfo(this); - } + } /// diff --git a/SunnyUI/Controls/UIImageListBox.cs b/SunnyUI/Controls/UIImageListBox.cs index cce9e830..e85bf624 100644 --- a/SunnyUI/Controls/UIImageListBox.cs +++ b/SunnyUI/Controls/UIImageListBox.cs @@ -338,16 +338,10 @@ namespace Sunny.UI } [ToolboxItem(false)] - private sealed class ImageListBox : ListBox, IStyleInterface + private sealed class ImageListBox : ListBox { private UIScrollBar bar; - [DefaultValue(false), Category("SunnyUI"), Description("绂佹鎺т欢璺熼殢绐椾綋缂╂斁")] - public bool ForbidControlScale { get; set; } - - [Browsable(false)] - public ControlScaleInfo DesignedRect { get; private set; } - /// /// Tag瀛楃涓 /// diff --git a/SunnyUI/Controls/UILabel.cs b/SunnyUI/Controls/UILabel.cs index 78b9409f..f0897d18 100644 --- a/SunnyUI/Controls/UILabel.cs +++ b/SunnyUI/Controls/UILabel.cs @@ -23,7 +23,6 @@ * 2022-03-19: V3.1.1 閲嶆瀯涓婚閰嶈壊 ******************************************************************************/ -using System; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; @@ -33,7 +32,7 @@ namespace Sunny.UI [ToolboxItem(true)] [DefaultEvent("Click")] [DefaultProperty("Text")] - public class UILabel : Label, IStyleInterface + public class UILabel : Label, IStyleInterface, IZoomScale { public UILabel() { @@ -44,23 +43,14 @@ namespace Sunny.UI } [DefaultValue(false), Category("SunnyUI"), Description("绂佹鎺т欢璺熼殢绐椾綋缂╂斁")] - public bool ForbidControlScale { get; set; } + public bool ZoomScaleDisabled { get; set; } [Browsable(false)] - public ControlScaleInfo DesignedRect { get; private set; } + public Rectangle ZoomScaleRect { get; set; } - protected override void OnVisibleChanged(EventArgs e) + public virtual void SetZoomScale(float scale) { - base.OnVisibleChanged(e); - SetDesignedSize(); - } - protected virtual void SetDesignedSize() - { - if (DesignedRect.Width == 0 && DesignedRect.Height == 0) - { - DesignedRect = new ControlScaleInfo(this); - } } private int angle; @@ -173,7 +163,7 @@ namespace Sunny.UI [ToolboxItem(true)] [DefaultEvent("Click")] [DefaultProperty("Text")] - public sealed class UILinkLabel : LinkLabel, IStyleInterface + public sealed class UILinkLabel : LinkLabel, IStyleInterface, IZoomScale { public UILinkLabel() { @@ -189,23 +179,14 @@ namespace Sunny.UI } [DefaultValue(false), Category("SunnyUI"), Description("绂佹鎺т欢璺熼殢绐椾綋缂╂斁")] - public bool ForbidControlScale { get; set; } + public bool ZoomScaleDisabled { get; set; } [Browsable(false)] - public ControlScaleInfo DesignedRect { get; private set; } + public Rectangle ZoomScaleRect { get; set; } - protected override void OnVisibleChanged(EventArgs e) + public void SetZoomScale(float scale) { - base.OnVisibleChanged(e); - SetDesignedSize(); - } - private void SetDesignedSize() - { - if (DesignedRect.Width == 0 && DesignedRect.Height == 0) - { - DesignedRect = new ControlScaleInfo(this); - } } [Browsable(false)] diff --git a/SunnyUI/Controls/UIListBox.cs b/SunnyUI/Controls/UIListBox.cs index 2ec8f861..3c7e3d62 100644 --- a/SunnyUI/Controls/UIListBox.cs +++ b/SunnyUI/Controls/UIListBox.cs @@ -605,16 +605,10 @@ namespace Sunny.UI /// ListBox /// [ToolboxItem(false)] - public sealed class ListBoxEx : ListBox, IStyleInterface + public sealed class ListBoxEx : ListBox { private UIScrollBar bar; - [Browsable(false)] - public ControlScaleInfo DesignedRect { get; private set; } - - [DefaultValue(false), Category("SunnyUI"), Description("绂佹鎺т欢璺熼殢绐椾綋缂╂斁")] - public bool ForbidControlScale { get; set; } - /// /// Tag瀛楃涓 /// diff --git a/SunnyUI/Controls/UINavBar.cs b/SunnyUI/Controls/UINavBar.cs index 79d89087..78821cf3 100644 --- a/SunnyUI/Controls/UINavBar.cs +++ b/SunnyUI/Controls/UINavBar.cs @@ -34,7 +34,7 @@ namespace Sunny.UI [DefaultEvent("MenuItemClick")] [DefaultProperty("Nodes")] [Designer("System.Windows.Forms.Design.TreeViewDesigner, " + AssemblyRefEx.SystemDesign)] - public sealed partial class UINavBar : ScrollableControl, IStyleInterface + public sealed partial class UINavBar : ScrollableControl, IStyleInterface, IZoomScale { public readonly TreeView Menu = new TreeView(); @@ -65,23 +65,16 @@ namespace Sunny.UI } [DefaultValue(false), Category("SunnyUI"), Description("绂佹鎺т欢璺熼殢绐椾綋缂╂斁")] - public bool ForbidControlScale { get; set; } + public bool ZoomScaleDisabled { get; set; } [Browsable(false)] - public ControlScaleInfo DesignedRect { get; private set; } + public Rectangle ZoomScaleRect { get; set; } - protected override void OnVisibleChanged(EventArgs e) + public void SetZoomScale(float scale) { - base.OnVisibleChanged(e); - SetDesignedSize(); - } - - private void SetDesignedSize() - { - if (DesignedRect.Width == 0 && DesignedRect.Height == 0) - { - DesignedRect = new ControlScaleInfo(this); - } + _nodeInterval = UIZoomScale.Calc(baseNodeInterval, scale); + nodeSize = UIZoomScale.Calc(baseNodeSize, scale); + Invalidate(); } [Browsable(false)] @@ -562,6 +555,7 @@ namespace Sunny.UI } private int _nodeInterval = 100; + private int baseNodeInterval = 100; [DefaultValue(100)] [Description("鏄剧ず鑿滃崟杈硅窛"), Category("SunnyUI")] @@ -572,13 +566,14 @@ namespace Sunny.UI { if (_nodeInterval != value) { - _nodeInterval = value; + baseNodeInterval = _nodeInterval = value; Invalidate(); } } } private Size nodeSize = new Size(130, 45); + private Size baseNodeSize = new Size(130, 45); [DefaultValue(typeof(Size), "130, 45")] [Description("鏄剧ず鑿滃崟澶у皬"), Category("SunnyUI")] @@ -589,7 +584,7 @@ namespace Sunny.UI { if (nodeSize != value) { - nodeSize = value; + baseNodeSize = nodeSize = value; Invalidate(); } } diff --git a/SunnyUI/Controls/UINavMenu.cs b/SunnyUI/Controls/UINavMenu.cs index d7e1f2e5..92cd8297 100644 --- a/SunnyUI/Controls/UINavMenu.cs +++ b/SunnyUI/Controls/UINavMenu.cs @@ -39,7 +39,7 @@ namespace Sunny.UI { [DefaultEvent("MenuItemClick")] [DefaultProperty("Nodes")] - public sealed class UINavMenu : TreeView, IStyleInterface + public sealed class UINavMenu : TreeView, IStyleInterface, IZoomScale { public delegate void OnMenuItemClick(TreeNode node, NavMenuItem item, int pageIndex); @@ -47,9 +47,6 @@ namespace Sunny.UI private readonly UIScrollBar Bar = new UIScrollBar(); - [DefaultValue(false), Category("SunnyUI"), Description("绂佹鎺т欢璺熼殢绐椾綋缂╂斁")] - public bool ForbidControlScale { get; set; } - public UINavMenu() { SetStyle(ControlStyles.DoubleBuffer | @@ -90,21 +87,15 @@ namespace Sunny.UI selectedHighColor = UIStyles.Blue.NavMenuMenuSelectedColor; } + [DefaultValue(false), Category("SunnyUI"), Description("绂佹鎺т欢璺熼殢绐椾綋缂╂斁")] + public bool ZoomScaleDisabled { get; set; } + [Browsable(false)] - public ControlScaleInfo DesignedRect { get; private set; } + public Rectangle ZoomScaleRect { get; set; } - protected override void OnVisibleChanged(EventArgs e) + public void SetZoomScale(float scale) { - base.OnVisibleChanged(e); - SetDesignedSize(); - } - private void SetDesignedSize() - { - if (DesignedRect.Width == 0 && DesignedRect.Height == 0) - { - DesignedRect = new ControlScaleInfo(this); - } } [Description("婊氬姩鏉″~鍏呴鑹"), Category("SunnyUI")] diff --git a/SunnyUI/Controls/UISmoothLabel.cs b/SunnyUI/Controls/UISmoothLabel.cs index b30266a6..ca05d977 100644 --- a/SunnyUI/Controls/UISmoothLabel.cs +++ b/SunnyUI/Controls/UISmoothLabel.cs @@ -32,7 +32,7 @@ namespace Sunny.UI [ToolboxItem(true)] [DefaultEvent("Click")] [DefaultProperty("Text")] - public sealed class UISmoothLabel : Label, IStyleInterface + public sealed class UISmoothLabel : Label, IStyleInterface, IZoomScale { public UISmoothLabel() { @@ -49,7 +49,15 @@ namespace Sunny.UI } [DefaultValue(false), Category("SunnyUI"), Description("绂佹鎺т欢璺熼殢绐椾綋缂╂斁")] - public bool ForbidControlScale { get; set; } + public bool ZoomScaleDisabled { get; set; } + + [Browsable(false)] + public Rectangle ZoomScaleRect { get; set; } + + public void SetZoomScale(float scale) + { + + } protected override void Dispose(bool disposing) { @@ -63,23 +71,6 @@ namespace Sunny.UI base.Dispose(disposing); } - [Browsable(false)] - public ControlScaleInfo DesignedRect { get; private set; } - - protected override void OnVisibleChanged(EventArgs e) - { - base.OnVisibleChanged(e); - SetDesignedSize(); - } - - private void SetDesignedSize() - { - if (DesignedRect.Width == 0 && DesignedRect.Height == 0) - { - DesignedRect = new ControlScaleInfo(this); - } - } - private PointF point; private SizeF drawSize; private Pen drawPen; diff --git a/SunnyUI/Controls/UISplitContainer.cs b/SunnyUI/Controls/UISplitContainer.cs index 1df07897..1debf8f2 100644 --- a/SunnyUI/Controls/UISplitContainer.cs +++ b/SunnyUI/Controls/UISplitContainer.cs @@ -26,7 +26,7 @@ using System.Windows.Forms; namespace Sunny.UI { - public sealed class UISplitContainer : SplitContainer, IStyleInterface + public sealed class UISplitContainer : SplitContainer, IStyleInterface, IZoomScale { private enum UIMouseType { @@ -68,9 +68,6 @@ namespace Sunny.UI private UIMouseType _uiMouseType; private readonly object EventCollapseClick = new object(); - [DefaultValue(false), Category("SunnyUI"), Description("绂佹鎺т欢璺熼殢绐椾綋缂╂斁")] - public bool ForbidControlScale { get; set; } - public UISplitContainer() { SetStyle(ControlStyles.UserPaint | @@ -82,21 +79,15 @@ namespace Sunny.UI Version = UIGlobal.Version; } + [DefaultValue(false), Category("SunnyUI"), Description("绂佹鎺т欢璺熼殢绐椾綋缂╂斁")] + public bool ZoomScaleDisabled { get; set; } + [Browsable(false)] - public ControlScaleInfo DesignedRect { get; private set; } + public Rectangle ZoomScaleRect { get; set; } - protected override void OnVisibleChanged(EventArgs e) + public void SetZoomScale(float scale) { - base.OnVisibleChanged(e); - SetDesignedSize(); - } - private void SetDesignedSize() - { - if (DesignedRect.Width == 0 && DesignedRect.Height == 0) - { - DesignedRect = new ControlScaleInfo(this); - } } private void SetStyleCustom(bool needRefresh = true) diff --git a/SunnyUI/Controls/UITabControl.cs b/SunnyUI/Controls/UITabControl.cs index 8ee8f8c0..0f0c9424 100644 --- a/SunnyUI/Controls/UITabControl.cs +++ b/SunnyUI/Controls/UITabControl.cs @@ -38,7 +38,7 @@ using System.Windows.Forms; namespace Sunny.UI { - public sealed class UITabControl : TabControl, IStyleInterface + public sealed class UITabControl : TabControl, IStyleInterface, IZoomScale { private readonly UITabControlHelper Helper; private int DrawedIndex = -1; @@ -73,23 +73,14 @@ namespace Sunny.UI } [DefaultValue(false), Category("SunnyUI"), Description("绂佹鎺т欢璺熼殢绐椾綋缂╂斁")] - public bool ForbidControlScale { get; set; } + public bool ZoomScaleDisabled { get; set; } [Browsable(false)] - public ControlScaleInfo DesignedRect { get; private set; } + public Rectangle ZoomScaleRect { get; set; } - protected override void OnVisibleChanged(EventArgs e) + public void SetZoomScale(float scale) { - base.OnVisibleChanged(e); - SetDesignedSize(); - } - private void SetDesignedSize() - { - if (DesignedRect.Width == 0 && DesignedRect.Height == 0) - { - DesignedRect = new ControlScaleInfo(this); - } } private ConcurrentDictionary TipsTexts = new ConcurrentDictionary(); diff --git a/SunnyUI/Controls/UITabControlMenu.cs b/SunnyUI/Controls/UITabControlMenu.cs index 70767b87..826547b7 100644 --- a/SunnyUI/Controls/UITabControlMenu.cs +++ b/SunnyUI/Controls/UITabControlMenu.cs @@ -27,7 +27,7 @@ using System.Windows.Forms; namespace Sunny.UI { - public sealed class UITabControlMenu : TabControl, IStyleInterface + public sealed class UITabControlMenu : TabControl, IStyleInterface, IZoomScale { public UITabControlMenu() { @@ -50,24 +50,15 @@ namespace Sunny.UI _fillColor = UIStyles.Blue.TabControlBackColor; } - [Browsable(false)] - public ControlScaleInfo DesignedRect { get; private set; } - [DefaultValue(false), Category("SunnyUI"), Description("绂佹鎺т欢璺熼殢绐椾綋缂╂斁")] - public bool ForbidControlScale { get; set; } + public bool ZoomScaleDisabled { get; set; } - protected override void OnVisibleChanged(EventArgs e) - { - base.OnVisibleChanged(e); - SetDesignedSize(); - } + [Browsable(false)] + public Rectangle ZoomScaleRect { get; set; } - private void SetDesignedSize() + public void SetZoomScale(float scale) { - if (DesignedRect.Width == 0 && DesignedRect.Height == 0) - { - DesignedRect = new ControlScaleInfo(this); - } + } [Browsable(false)] diff --git a/SunnyUI/Controls/UITableLayoutPanel.cs b/SunnyUI/Controls/UITableLayoutPanel.cs index f9b4b219..356c2262 100644 --- a/SunnyUI/Controls/UITableLayoutPanel.cs +++ b/SunnyUI/Controls/UITableLayoutPanel.cs @@ -21,7 +21,6 @@ ******************************************************************************/ using System.ComponentModel; -using System.Drawing; using System.Windows.Forms; namespace Sunny.UI @@ -33,15 +32,9 @@ namespace Sunny.UI Version = UIGlobal.Version; } - [Browsable(false)] - public ControlScaleInfo DesignedRect { get; private set; } - [Browsable(false)] public bool IsScaled { get; private set; } - [DefaultValue(false), Category("SunnyUI"), Description("绂佹鎺т欢璺熼殢绐椾綋缂╂斁")] - public bool ForbidControlScale { get; set; } - public void SetDPIScale() { if (!IsScaled) diff --git a/SunnyUI/Controls/UIUserControl.cs b/SunnyUI/Controls/UIUserControl.cs index f340c961..77eb4015 100644 --- a/SunnyUI/Controls/UIUserControl.cs +++ b/SunnyUI/Controls/UIUserControl.cs @@ -31,7 +31,7 @@ namespace Sunny.UI { [Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(System.ComponentModel.Design.IDesigner))] [DefaultEvent("Click"), DefaultProperty("Text")] - public partial class UIUserControl : UserControl, IStyleInterface + public partial class UIUserControl : UserControl, IStyleInterface, IZoomScale { private int radius = 5; protected Color rectColor = UIStyles.Blue.PanelRectColor; @@ -51,7 +51,15 @@ namespace Sunny.UI } [DefaultValue(false), Category("SunnyUI"), Description("绂佹鎺т欢璺熼殢绐椾綋缂╂斁")] - public bool ForbidControlScale { get; set; } + public bool ZoomScaleDisabled { get; set; } + + [Browsable(false)] + public Rectangle ZoomScaleRect { get; set; } + + public virtual void SetZoomScale(float scale) + { + + } [Browsable(false), DefaultValue(false)] public bool IsScaled { get; set; } @@ -345,9 +353,6 @@ namespace Sunny.UI } } - [Browsable(false)] - public ControlScaleInfo DesignedRect { get; private set; } - protected override void OnVisibleChanged(EventArgs e) { base.OnVisibleChanged(e); @@ -355,16 +360,6 @@ namespace Sunny.UI { AutoScaleMode = AutoScaleMode.None; } - - SetDesignedSize(); - } - - protected virtual void SetDesignedSize() - { - if (DesignedRect.Width == 0 && DesignedRect.Height == 0) - { - DesignedRect = new ControlScaleInfo(this); - } } protected override void OnPaint(PaintEventArgs e) diff --git a/SunnyUI/Forms/UIForm.cs b/SunnyUI/Forms/UIForm.cs index d946cafa..210e8e78 100644 --- a/SunnyUI/Forms/UIForm.cs +++ b/SunnyUI/Forms/UIForm.cs @@ -83,7 +83,7 @@ namespace Sunny.UI } [DefaultValue(false), Category("SunnyUI"), Description("绂佹鎺т欢璺熼殢绐椾綋缂╂斁")] - public bool ForbidControlScale { get; set; } + public bool ZoomScaleDisabled { get; set; } [Browsable(false)] public bool IsScaled { get; private set; } @@ -115,52 +115,52 @@ namespace Sunny.UI } } - private void SetDesignedSize() + private void SetZoomScaleRect() { - if (DesignedRect.Width == 0 && DesignedRect.Height == 0) + if (ZoomScaleRect.Width == 0 && ZoomScaleRect.Height == 0) { - DesignedRect = new ControlScaleInfo(DesignedSize.Width, DesignedSize.Height, 0, 0); + ZoomScaleRect = new Rectangle(ZoomScaleSize.Width, ZoomScaleSize.Height, 0, 0); } - if (DesignedRect.Width == 0 && DesignedRect.Height == 0) + if (ZoomScaleRect.Width == 0 && ZoomScaleRect.Height == 0) { - DesignedRect = new ControlScaleInfo(this); + ZoomScaleRect = new Rectangle(Left, Top, Width, Height); } - DesignSizeChanged?.Invoke(this, DesignedRect); + ZoomScaleRectChanged?.Invoke(this, ZoomScaleRect); } [DefaultValue(typeof(Size), "0, 0")] [Description("璁捐鐣岄潰澶у皬"), Category("SunnyUI")] - public Size DesignedSize + public Size ZoomScaleSize { get; set; } [Browsable(false)] - public ControlScaleInfo DesignedRect { get; private set; } + public Rectangle ZoomScaleRect { get; set; } - private void SetControlScale() + private void SetZoomScale() { - if (ForbidControlScale) return; - if (!UIStyles.DPIScale || !UIStyles.ControlScale) return; - if (DesignedRect.Width == 0 || DesignedRect.Height == 0) return; + 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 / DesignedRect.Width, Height * 1.0f / DesignedRect.Height); + float scale = Math.Min(Width * 1.0f / ZoomScaleRect.Width, Height * 1.0f / ZoomScaleRect.Height); if (scale.EqualsFloat(0)) return; - foreach (Control control in this.GetAllDPIScaleControls()) + foreach (Control control in this.GetAllZoomScaleControls()) { - if (control is IStyleInterface) + if (control is IZoomScale ctrl) { - UIDPIScale.SetControlScale(control, scale); + UIZoomScale.SetZoomScale(control, scale); } } - ControlScaleChanged?.Invoke(this, scale); + ZoomScaleChanged?.Invoke(this, scale); } - public event OnControlScaleChanged ControlScaleChanged; + public event OnZoomScaleChanged ZoomScaleChanged; public void ResetDPIScale() { @@ -1318,7 +1318,7 @@ namespace Sunny.UI protected override void OnSizeChanged(EventArgs e) { base.OnSizeChanged(e); - SetControlScale(); + SetZoomScale(); CalcSystemBoxPos(); if (isShow) @@ -1352,10 +1352,10 @@ namespace Sunny.UI SetRadius(); isShow = true; SetDPIScale(); - SetDesignedSize(); + SetZoomScaleRect(); } - public event OnDesignSizeChanged DesignSizeChanged; + public event OnZoomScaleRectChanged ZoomScaleRectChanged; /// /// 鏄惁鏄剧ず鍦嗚 diff --git a/SunnyUI/Forms/UIFormHelper.cs b/SunnyUI/Forms/UIFormHelper.cs index 572f36ec..17a3d977 100644 --- a/SunnyUI/Forms/UIFormHelper.cs +++ b/SunnyUI/Forms/UIFormHelper.cs @@ -30,9 +30,9 @@ using System.Windows.Forms; namespace Sunny.UI { - public delegate void OnControlScaleChanged(object sender, float scale); + public delegate void OnZoomScaleChanged(object sender, float scale); - public delegate void OnDesignSizeChanged(object sender, ControlScaleInfo info); + public delegate void OnZoomScaleRectChanged(object sender, Rectangle info); public static class UIMessageDialog { diff --git a/SunnyUI/Frames/UIPage.cs b/SunnyUI/Frames/UIPage.cs index a1e0f0c5..6e96631f 100644 --- a/SunnyUI/Frames/UIPage.cs +++ b/SunnyUI/Frames/UIPage.cs @@ -37,7 +37,7 @@ using System.Windows.Forms; namespace Sunny.UI { [DefaultEvent("Initialize")] - public partial class UIPage : Form, IStyleInterface, ISymbol + public partial class UIPage : Form, IStyleInterface, ISymbol, IZoomScale { public readonly Guid Guid = Guid.NewGuid(); private Color _rectColor = UIColor.Blue; @@ -77,23 +77,14 @@ namespace Sunny.UI } [DefaultValue(false), Category("SunnyUI"), Description("绂佹鎺т欢璺熼殢绐椾綋缂╂斁")] - public bool ForbidControlScale { get; set; } + public bool ZoomScaleDisabled { get; set; } [Browsable(false)] - public ControlScaleInfo DesignedRect { get; private set; } + public Rectangle ZoomScaleRect { get; set; } - protected override void OnVisibleChanged(EventArgs e) + public virtual void SetZoomScale(float scale) { - base.OnVisibleChanged(e); - SetDesignedSize(); - } - protected virtual void SetDesignedSize() - { - if (DesignedRect.Width == 0 && DesignedRect.Height == 0) - { - DesignedRect = new ControlScaleInfo(this); - } } [Browsable(false)] diff --git a/SunnyUI/Style/UIDPIScale.cs b/SunnyUI/Style/UIDPIScale.cs index b0a485ed..ebffbd4e 100644 --- a/SunnyUI/Style/UIDPIScale.cs +++ b/SunnyUI/Style/UIDPIScale.cs @@ -95,7 +95,6 @@ namespace Sunny.UI if (con is UIPagination) continue; if (con is UIRichTextBox) continue; if (con is UITreeView) continue; - if (con is UINavBar) continue; if (con.Controls.Count > 0) { @@ -106,86 +105,29 @@ namespace Sunny.UI return list; } - internal static int Calc(int size, float scale) + internal static List GetAllZoomScaleControls(this Control control) { - return (int)(size * scale + 0.5); - } - - internal static void SetControlScale(Control control, float scale) - { - if (scale.EqualsFloat(0)) return; - - if (control is IStyleInterface ctrl) + var list = new List(); + foreach (Control con in control.Controls) { - if (ctrl.ForbidControlScale) + if (con is IZoomScale) + list.Add(con); + + if (con is UITextBox) continue; + if (con is UIDropControl) continue; + if (con is UIListBox) continue; + if (con is UIImageListBox) continue; + if (con is UIPagination) continue; + if (con is UIRichTextBox) continue; + if (con is UITreeView) continue; + + if (con.Controls.Count > 0) { - return; - } - - if (control is IControlScale sc) - { - sc.SetControlScale(scale); - } - - if (control.Dock == DockStyle.Fill) - { - return; - } - - var rect = ctrl.DesignedRect; - switch (control.Dock) - { - case DockStyle.None: - control.Height = Calc(rect.Height, scale); - control.Width = Calc(rect.Width, scale); - - if (control.Parent != null) - { - if ((control.Anchor & AnchorStyles.Left) == AnchorStyles.Left) - { - control.Left = Calc(rect.XInterval, scale); - } - - if ((control.Anchor & AnchorStyles.Right) == AnchorStyles.Right) - { - int right = Calc(rect.XInterval, scale); - control.Left = control.Parent.Width - right - control.Width; - } - - if ((control.Anchor & AnchorStyles.Top) == AnchorStyles.Top) - { - if (control.Parent is UIForm form && form.ShowTitle) - control.Top = Calc(rect.YInterval - form.TitleHeight, scale) + form.TitleHeight; - else - control.Top = Calc(rect.YInterval, scale); - } - - if ((control.Anchor & AnchorStyles.Bottom) == AnchorStyles.Bottom) - { - int bottom = Calc(rect.YInterval, scale); - control.Top = control.Parent.Height - bottom - control.Height; - } - } - - break; - case DockStyle.Top: - control.Height = Calc(rect.Height, scale); - break; - case DockStyle.Bottom: - control.Height = Calc(rect.Height, scale); - break; - case DockStyle.Left: - control.Width = Calc(rect.Width, scale); - break; - case DockStyle.Right: - control.Width = Calc(rect.Width, scale); - break; - case DockStyle.Fill: - break; - default: - break; + list.AddRange(GetAllZoomScaleControls(con)); } } + + return list; } } } diff --git a/SunnyUI/Style/UIStyle.cs b/SunnyUI/Style/UIStyle.cs index 6891ad66..0f2d6bda 100644 --- a/SunnyUI/Style/UIStyle.cs +++ b/SunnyUI/Style/UIStyle.cs @@ -59,61 +59,6 @@ namespace Sunny.UI bool IsScaled { get; } void SetDPIScale(); - - ControlScaleInfo DesignedRect { get; } - - bool ForbidControlScale { get; set; } - } - - public interface IControlScale - { - void SetControlScale(float scale); - } - - public struct ControlScaleInfo - { - public int XInterval { get; } - public int YInterval { get; } - public int Width { get; } - public int Height { get; } - - public ControlScaleInfo(int width, int height, int xInterval, int yInterval) - { - Width = width; - Height = height; - XInterval = xInterval; - YInterval = yInterval; - } - - public ControlScaleInfo(Control control) - { - Width = control.Width; - Height = control.Height; - XInterval = 0; - YInterval = 0; - if (control.Parent != null) - { - if ((control.Anchor & AnchorStyles.Left) == AnchorStyles.Left) - { - XInterval = control.Left; - } - - if ((control.Anchor & AnchorStyles.Right) == AnchorStyles.Right) - { - XInterval = control.Parent.Width - control.Right; - } - - if ((control.Anchor & AnchorStyles.Top) == AnchorStyles.Top) - { - YInterval = control.Top; - } - - if ((control.Anchor & AnchorStyles.Bottom) == AnchorStyles.Bottom) - { - YInterval = control.Parent.Height - control.Bottom; - } - } - } } /// diff --git a/SunnyUI/Style/UIStyles.cs b/SunnyUI/Style/UIStyles.cs index 587c1e04..31eaddf2 100644 --- a/SunnyUI/Style/UIStyles.cs +++ b/SunnyUI/Style/UIStyles.cs @@ -38,7 +38,7 @@ namespace Sunny.UI { public static bool DPIScale { get; set; } - public static bool ControlScale { get; set; } + public static bool ZoomScale { get; set; } public static float FontSize { get; set; } = 12; diff --git a/SunnyUI/Style/UIZoomScale.cs b/SunnyUI/Style/UIZoomScale.cs new file mode 100644 index 00000000..f9000292 --- /dev/null +++ b/SunnyUI/Style/UIZoomScale.cs @@ -0,0 +1,151 @@ +锘縰sing System.Drawing; +using System.Windows.Forms; + +namespace Sunny.UI +{ + public interface IZoomScale + { + void SetZoomScale(float scale); + + Rectangle ZoomScaleRect { get; set; } + + bool ZoomScaleDisabled { get; set; } + } + + internal static class UIZoomScale + { + public static Rectangle Create(Control control) + { + if (control is IZoomScale ctrl) + { + if (ctrl.ZoomScaleRect.Width > 0 || ctrl.ZoomScaleRect.Height > 0) + { + return ctrl.ZoomScaleRect; + } + else + { + int Width = control.Width; + int Height = control.Height; + int XInterval = 0; + int YInterval = 0; + if (control.Parent != null) + { + if ((control.Anchor & AnchorStyles.Left) == AnchorStyles.Left) + { + XInterval = control.Left; + } + + if ((control.Anchor & AnchorStyles.Right) == AnchorStyles.Right) + { + XInterval = control.Parent.Width - control.Right; + } + + if ((control.Anchor & AnchorStyles.Top) == AnchorStyles.Top) + { + YInterval = control.Top; + } + + if ((control.Anchor & AnchorStyles.Bottom) == AnchorStyles.Bottom) + { + YInterval = control.Parent.Height - control.Bottom; + } + } + + return new Rectangle(XInterval, YInterval, Width, Height); + } + } + else + { + return new Rectangle(control.Left, control.Top, control.Width, control.Height); + } + } + + internal static int Calc(int size, float scale) + { + return (int)(size * scale + 0.5); + } + + internal static Size Calc(Size size, float scale) + { + return new Size(Calc(size.Width, scale), Calc(size.Height, scale)); + } + + internal static void SetZoomScale(Control control, float scale) + { + if (scale.EqualsFloat(0)) return; + + if (control is IZoomScale ctrl) + { + if (ctrl.ZoomScaleDisabled) + { + return; + } + + //璁剧疆鎺т欢鐨勭缉鏀惧弬鏁 + ctrl.ZoomScaleRect = UIZoomScale.Create(control); + + //璁剧疆鑷畾涔夌殑缂╂斁锛屼緥濡俇IAvatar + ctrl.SetZoomScale(scale); + + if (control.Dock == DockStyle.Fill) + { + return; + } + + var rect = ctrl.ZoomScaleRect; + switch (control.Dock) + { + case DockStyle.None: + control.Height = Calc(rect.Height, scale); + control.Width = Calc(rect.Width, scale); + + if (control.Parent != null) + { + if ((control.Anchor & AnchorStyles.Left) == AnchorStyles.Left) + { + control.Left = Calc(rect.Left, scale); + } + + if ((control.Anchor & AnchorStyles.Right) == AnchorStyles.Right) + { + int right = Calc(rect.Left, scale); + control.Left = control.Parent.Width - right - control.Width; + } + + if ((control.Anchor & AnchorStyles.Top) == AnchorStyles.Top) + { + if (control.Parent is UIForm form && form.ShowTitle) + control.Top = Calc(rect.Top - form.TitleHeight, scale) + form.TitleHeight; + else + control.Top = Calc(rect.Top, scale); + } + + if ((control.Anchor & AnchorStyles.Bottom) == AnchorStyles.Bottom) + { + int bottom = Calc(rect.Top, scale); + control.Top = control.Parent.Height - bottom - control.Height; + } + } + + break; + case DockStyle.Top: + control.Height = Calc(rect.Height, scale); + break; + case DockStyle.Bottom: + control.Height = Calc(rect.Height, scale); + break; + case DockStyle.Left: + control.Width = Calc(rect.Width, scale); + break; + case DockStyle.Right: + control.Width = Calc(rect.Width, scale); + break; + case DockStyle.Fill: + break; + default: + break; + } + } + } + } +}