diff --git a/Bin/net40/SunnyUI.dll b/Bin/net40/SunnyUI.dll index 15d9a970..b7a21db2 100644 Binary files a/Bin/net40/SunnyUI.dll and b/Bin/net40/SunnyUI.dll differ diff --git a/SunnyUI/Controls/Color/UIColorWheel.cs b/SunnyUI/Controls/Color/UIColorWheel.cs index 536b5c0c..17742b84 100644 --- a/SunnyUI/Controls/Color/UIColorWheel.cs +++ b/SunnyUI/Controls/Color/UIColorWheel.cs @@ -33,6 +33,12 @@ namespace Sunny.UI } } + [DefaultValue(false), Category("SunnyUI"), Description("ֹؼ洰")] + public bool ForbidControlScale { get; set; } + + [Browsable(false), DefaultValue(typeof(Size), "0, 0")] + public ControlScaleInfo DesignedRect { get; private set; } + [Browsable(false)] public bool IsScaled { get; private set; } diff --git a/SunnyUI/Controls/Color/UILabelRotate.cs b/SunnyUI/Controls/Color/UILabelRotate.cs index 715c00cf..12abba8d 100644 --- a/SunnyUI/Controls/Color/UILabelRotate.cs +++ b/SunnyUI/Controls/Color/UILabelRotate.cs @@ -11,6 +11,12 @@ namespace Sunny.UI private ContentAlignment m_rotatePointAlignment = ContentAlignment.MiddleCenter; private ContentAlignment m_textAlignment = ContentAlignment.MiddleLeft; + [Browsable(false), DefaultValue(typeof(Size), "0, 0")] + public ControlScaleInfo DesignedRect { get; private set; } + + [DefaultValue(false), Category("SunnyUI"), Description("ֹؼ洰")] + public bool ForbidControlScale { get; set; } + [Browsable(false)] public bool IsScaled { get; private set; } diff --git a/SunnyUI/Controls/UIAvatar.cs b/SunnyUI/Controls/UIAvatar.cs index b73dc39b..7b390d63 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 + public sealed class UIAvatar : UIControl, ISymbol, IControlScale { /// /// 头像图标类型 @@ -351,5 +351,10 @@ namespace Sunny.UI PaintAgain?.Invoke(this, e); } + + public void SetControlScale(float scale) + { + throw new NotImplementedException(); + } } } \ No newline at end of file diff --git a/SunnyUI/Controls/UIContextMenuStrip.cs b/SunnyUI/Controls/UIContextMenuStrip.cs index 2648dde4..5d9b417c 100644 --- a/SunnyUI/Controls/UIContextMenuStrip.cs +++ b/SunnyUI/Controls/UIContextMenuStrip.cs @@ -42,6 +42,12 @@ namespace Sunny.UI BackColor = UIStyles.Blue.ContextMenuColor; } + [DefaultValue(false), Category("SunnyUI"), Description("禁止控件跟随窗体缩放")] + public bool ForbidControlScale { get; set; } + + [Browsable(false), DefaultValue(typeof(Size), "0, 0")] + public ControlScaleInfo DesignedRect { get; private set; } + [Browsable(false), DefaultValue(false)] public bool IsScaled { get; set; } diff --git a/SunnyUI/Controls/UIControl.cs b/SunnyUI/Controls/UIControl.cs index ba4289f4..68648699 100644 --- a/SunnyUI/Controls/UIControl.cs +++ b/SunnyUI/Controls/UIControl.cs @@ -49,6 +49,26 @@ namespace Sunny.UI base.MinimumSize = new Size(1, 1); } + [Browsable(false), DefaultValue(typeof(Size), "0, 0")] + 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; } + protected bool selected; [Browsable(false), DefaultValue(false)] diff --git a/SunnyUI/Controls/UIDataGridView.cs b/SunnyUI/Controls/UIDataGridView.cs index 66d383ef..8a4d31d9 100644 --- a/SunnyUI/Controls/UIDataGridView.cs +++ b/SunnyUI/Controls/UIDataGridView.cs @@ -100,6 +100,26 @@ namespace Sunny.UI HorizontalScrollBar.VisibleChanged += HorizontalScrollBar_VisibleChanged; } + [DefaultValue(false), Category("SunnyUI"), Description("禁止控件跟随窗体缩放")] + public bool ForbidControlScale { get; set; } + + [Browsable(false), DefaultValue(typeof(Size), "0, 0")] + 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); + } + } + [Browsable(false)] public bool IsScaled { get; private set; } diff --git a/SunnyUI/Controls/UIImageButton.cs b/SunnyUI/Controls/UIImageButton.cs index 775d0ca7..a02f2def 100644 --- a/SunnyUI/Controls/UIImageButton.cs +++ b/SunnyUI/Controls/UIImageButton.cs @@ -44,6 +44,26 @@ namespace Sunny.UI private ContentAlignment textAlign = ContentAlignment.MiddleCenter; private Color foreColor = UIFontColor.Primary; + [Browsable(false), DefaultValue(typeof(Size), "0, 0")] + public ControlScaleInfo DesignedRect { get; private set; } + + [DefaultValue(false), Category("SunnyUI"), Description("禁止控件跟随窗体缩放")] + public bool ForbidControlScale { get; 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); + } + } + /// /// 主题样式 /// diff --git a/SunnyUI/Controls/UIImageListBox.cs b/SunnyUI/Controls/UIImageListBox.cs index ecb341bc..5bf6328d 100644 --- a/SunnyUI/Controls/UIImageListBox.cs +++ b/SunnyUI/Controls/UIImageListBox.cs @@ -342,6 +342,12 @@ namespace Sunny.UI { private UIScrollBar bar; + [DefaultValue(false), Category("SunnyUI"), Description("禁止控件跟随窗体缩放")] + public bool ForbidControlScale { get; set; } + + [Browsable(false), DefaultValue(typeof(Size), "0, 0")] + public ControlScaleInfo DesignedRect { get; private set; } + /// /// Tag字符串 /// diff --git a/SunnyUI/Controls/UILabel.cs b/SunnyUI/Controls/UILabel.cs index 599db46a..efdf8c3c 100644 --- a/SunnyUI/Controls/UILabel.cs +++ b/SunnyUI/Controls/UILabel.cs @@ -23,6 +23,7 @@ * 2022-03-19: V3.1.1 重构主题配色 ******************************************************************************/ +using System; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; @@ -42,6 +43,26 @@ namespace Sunny.UI foreColor = UIStyles.Blue.LabelForeColor; } + [DefaultValue(false), Category("SunnyUI"), Description("禁止控件跟随窗体缩放")] + public bool ForbidControlScale { get; set; } + + [Browsable(false), DefaultValue(typeof(Size), "0, 0")] + 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); + } + } + private int angle; [DefaultValue(0), Category("SunnyUI"), Description("居中时旋转角度")] @@ -167,6 +188,26 @@ namespace Sunny.UI base.LinkColor = linkColor = UIColor.Blue; } + [DefaultValue(false), Category("SunnyUI"), Description("禁止控件跟随窗体缩放")] + public bool ForbidControlScale { get; set; } + + [Browsable(false), DefaultValue(typeof(Size), "0, 0")] + 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); + } + } + [Browsable(false)] public bool IsScaled { get; private set; } diff --git a/SunnyUI/Controls/UIListBox.cs b/SunnyUI/Controls/UIListBox.cs index 7ffb8c94..bbe2e2ab 100644 --- a/SunnyUI/Controls/UIListBox.cs +++ b/SunnyUI/Controls/UIListBox.cs @@ -609,6 +609,12 @@ namespace Sunny.UI { private UIScrollBar bar; + [Browsable(false), DefaultValue(typeof(Size), "0, 0")] + public ControlScaleInfo DesignedRect { get; private set; } + + [DefaultValue(false), Category("SunnyUI"), Description("禁止控件跟随窗体缩放")] + public bool ForbidControlScale { get; set; } + /// /// Tag字符串 /// diff --git a/SunnyUI/Controls/UIMarkLabel.cs b/SunnyUI/Controls/UIMarkLabel.cs index c5f4a380..6e608d0c 100644 --- a/SunnyUI/Controls/UIMarkLabel.cs +++ b/SunnyUI/Controls/UIMarkLabel.cs @@ -29,7 +29,7 @@ namespace Sunny.UI [ToolboxItem(true)] [DefaultEvent("Click")] [DefaultProperty("Text")] - public class UIMarkLabel : UILabel + public sealed class UIMarkLabel : UILabel { public UIMarkLabel() { diff --git a/SunnyUI/Controls/UINavBar.cs b/SunnyUI/Controls/UINavBar.cs index 0437d5ce..56dcce38 100644 --- a/SunnyUI/Controls/UINavBar.cs +++ b/SunnyUI/Controls/UINavBar.cs @@ -64,6 +64,26 @@ namespace Sunny.UI selectedHighColor = UIStyles.Blue.NavBarMenuSelectedColor; } + [DefaultValue(false), Category("SunnyUI"), Description("禁止控件跟随窗体缩放")] + public bool ForbidControlScale { get; set; } + + [Browsable(false), DefaultValue(typeof(Size), "0, 0")] + 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); + } + } + [Browsable(false)] public bool IsScaled { get; private set; } diff --git a/SunnyUI/Controls/UINavMenu.cs b/SunnyUI/Controls/UINavMenu.cs index 55e61b8d..10e1ca60 100644 --- a/SunnyUI/Controls/UINavMenu.cs +++ b/SunnyUI/Controls/UINavMenu.cs @@ -47,6 +47,9 @@ namespace Sunny.UI private readonly UIScrollBar Bar = new UIScrollBar(); + [DefaultValue(false), Category("SunnyUI"), Description("禁止控件跟随窗体缩放")] + public bool ForbidControlScale { get; set; } + public UINavMenu() { SetStyle(ControlStyles.DoubleBuffer | @@ -87,6 +90,23 @@ namespace Sunny.UI selectedHighColor = UIStyles.Blue.NavMenuMenuSelectedColor; } + [Browsable(false), DefaultValue(typeof(Size), "0, 0")] + 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); + } + } + [Description("滚动条填充颜色"), Category("SunnyUI")] [DefaultValue(typeof(Color), "56, 56, 56")] public Color ScrollFillColor diff --git a/SunnyUI/Controls/UINavMenuHelper.cs b/SunnyUI/Controls/UINavMenuHelper.cs index 7b93d9d4..9f9abb41 100644 --- a/SunnyUI/Controls/UINavMenuHelper.cs +++ b/SunnyUI/Controls/UINavMenuHelper.cs @@ -334,30 +334,48 @@ namespace Sunny.UI return CreateTabIfNotExists(new NavMenuItem(guid)); } - public void SelectPage(int pageIndex) + public bool SelectPage(int pageIndex) { - if (pageIndex < 0) return; + if (pageIndex < 0) + { + return false; + } + foreach (var item in PageItems) { if (item.Value.PageIndex == pageIndex && item.Key != null) { if (tabControl.TabPages.Contains(item.Key)) + { tabControl.SelectTab(item.Key); + return true; + } } } + + return false; } - public void SelectPage(Guid guid) + public bool SelectPage(Guid guid) { - if (guid == Guid.Empty) return; + if (guid == Guid.Empty) + { + return false; + } + foreach (var item in PageItems) { if (item.Value.PageGuid == guid && item.Key != null) { if (tabControl.TabPages.Contains(item.Key)) + { tabControl.SelectTab(item.Key); + return true; + } } } + + return false; } public UIPage GetPage(int pageIndex) diff --git a/SunnyUI/Controls/UISmoothLabel.cs b/SunnyUI/Controls/UISmoothLabel.cs index e288c85a..f0e65852 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 class UISmoothLabel : Label, IStyleInterface + public sealed class UISmoothLabel : Label, IStyleInterface { public UISmoothLabel() { @@ -48,6 +48,9 @@ namespace Sunny.UI Size = new Size(300, 60); } + [DefaultValue(false), Category("SunnyUI"), Description("禁止控件跟随窗体缩放")] + public bool ForbidControlScale { get; set; } + protected override void Dispose(bool disposing) { if (disposing) @@ -60,6 +63,23 @@ namespace Sunny.UI base.Dispose(disposing); } + [Browsable(false), DefaultValue(typeof(Size), "0, 0")] + 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; @@ -103,7 +123,7 @@ namespace Sunny.UI } } - protected void SetStyleCustom(bool needRefresh = true) + private void SetStyleCustom(bool needRefresh = true) { _style = UIStyle.Custom; if (needRefresh) Invalidate(); @@ -129,7 +149,7 @@ namespace Sunny.UI [Description("获取或设置可以自定义主题风格"), Category("SunnyUI")] public bool StyleCustomMode { get; set; } - public virtual void SetStyleColor(UIBaseStyle uiColor) + public void SetStyleColor(UIBaseStyle uiColor) { foreColor = uiColor.SmoothLabelForeColor; rectColor = uiColor.SmoothLabelRectColor; @@ -163,7 +183,7 @@ namespace Sunny.UI Invalidate(); } - protected Color rectColor; + private Color rectColor; /// /// 边框颜色 diff --git a/SunnyUI/Controls/UISplitContainer.cs b/SunnyUI/Controls/UISplitContainer.cs index 378b839f..d9dfb578 100644 --- a/SunnyUI/Controls/UISplitContainer.cs +++ b/SunnyUI/Controls/UISplitContainer.cs @@ -26,7 +26,7 @@ using System.Windows.Forms; namespace Sunny.UI { - public class UISplitContainer : SplitContainer, IStyleInterface + public sealed class UISplitContainer : SplitContainer, IStyleInterface { private enum UIMouseType { @@ -68,6 +68,9 @@ 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 | @@ -79,7 +82,24 @@ namespace Sunny.UI Version = UIGlobal.Version; } - protected void SetStyleCustom(bool needRefresh = true) + [Browsable(false), DefaultValue(typeof(Size), "0, 0")] + 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 void SetStyleCustom(bool needRefresh = true) { _style = UIStyle.Custom; if (needRefresh) Invalidate(); @@ -163,9 +183,9 @@ namespace Sunny.UI } } - protected virtual int DefaultCollapseWidth => 80; + private int DefaultCollapseWidth => 80; - protected virtual int DefaultArrowWidth => 24; + private int DefaultArrowWidth => 24; private Rectangle CollapseRect { @@ -227,7 +247,7 @@ namespace Sunny.UI } } - protected UIStyle _style = UIStyle.Blue; + private UIStyle _style = UIStyle.Blue; /// /// 主题样式 @@ -317,7 +337,7 @@ namespace Sunny.UI } } - protected virtual void OnCollapseClick(EventArgs e) + private void OnCollapseClick(EventArgs e) { SplitPanelState = SplitPanelState == UISplitPanelState.Collapsed ? UISplitPanelState.Expanded : UISplitPanelState.Collapsed; @@ -384,7 +404,7 @@ namespace Sunny.UI } } - protected Point[] GetHandlePoints() + private Point[] GetHandlePoints() { bool bCollapsed = SplitPanelState == UISplitPanelState.Collapsed; diff --git a/SunnyUI/Controls/UITabControl.cs b/SunnyUI/Controls/UITabControl.cs index a641c941..16db46c0 100644 --- a/SunnyUI/Controls/UITabControl.cs +++ b/SunnyUI/Controls/UITabControl.cs @@ -72,6 +72,26 @@ namespace Sunny.UI _fillColor = UIStyles.Blue.TabControlBackColor; } + [DefaultValue(false), Category("SunnyUI"), Description("禁止控件跟随窗体缩放")] + public bool ForbidControlScale { get; set; } + + [Browsable(false), DefaultValue(typeof(Size), "0, 0")] + 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 ConcurrentDictionary TipsTexts = new ConcurrentDictionary(); public void SetTipsText(TabPage tabPage, string tipsText) @@ -192,9 +212,9 @@ namespace Sunny.UI [Description("是否禁用Ctrl+Tab"), Category("SunnyUI")] public bool ForbidCtrlTab { get; set; } = true; - public void SelectPage(int pageIndex) => Helper.SelectPage(pageIndex); + public bool SelectPage(int pageIndex) => Helper.SelectPage(pageIndex); - public void SelectPage(Guid pageGuid) => Helper.SelectPage(pageGuid); + public bool SelectPage(Guid pageGuid) => Helper.SelectPage(pageGuid); public void AddPage(UIPage page) => Helper.AddPage(page); diff --git a/SunnyUI/Controls/UITabControlMenu.cs b/SunnyUI/Controls/UITabControlMenu.cs index 95115f76..6f2cc987 100644 --- a/SunnyUI/Controls/UITabControlMenu.cs +++ b/SunnyUI/Controls/UITabControlMenu.cs @@ -50,6 +50,26 @@ namespace Sunny.UI _fillColor = UIStyles.Blue.TabControlBackColor; } + [Browsable(false), DefaultValue(typeof(Size), "0, 0")] + public ControlScaleInfo DesignedRect { get; private set; } + + [DefaultValue(false), Category("SunnyUI"), Description("禁止控件跟随窗体缩放")] + public bool ForbidControlScale { get; 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); + } + } + [Browsable(false)] public bool IsScaled { get; private set; } diff --git a/SunnyUI/Controls/UITableLayoutPanel.cs b/SunnyUI/Controls/UITableLayoutPanel.cs index f0416574..0cf006f8 100644 --- a/SunnyUI/Controls/UITableLayoutPanel.cs +++ b/SunnyUI/Controls/UITableLayoutPanel.cs @@ -21,20 +21,27 @@ ******************************************************************************/ using System.ComponentModel; +using System.Drawing; using System.Windows.Forms; namespace Sunny.UI { - public class UITableLayoutPanel : TableLayoutPanel, IStyleInterface + public sealed class UITableLayoutPanel : TableLayoutPanel, IStyleInterface { public UITableLayoutPanel() { Version = UIGlobal.Version; } + [Browsable(false), DefaultValue(typeof(Size), "0, 0")] + 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) @@ -66,7 +73,7 @@ namespace Sunny.UI get; set; } - protected UIStyle _style = UIStyle.Blue; + private UIStyle _style = UIStyle.Blue; /// /// 主题样式 diff --git a/SunnyUI/Controls/UIUserControl.cs b/SunnyUI/Controls/UIUserControl.cs index e4408f7f..10694de1 100644 --- a/SunnyUI/Controls/UIUserControl.cs +++ b/SunnyUI/Controls/UIUserControl.cs @@ -50,11 +50,15 @@ namespace Sunny.UI SetStyleFlags(true, false); } + [DefaultValue(false), Category("SunnyUI"), Description("禁止控件跟随窗体缩放")] + public bool ForbidControlScale { get; set; } + [Browsable(false), DefaultValue(false)] public bool IsScaled { get; set; } public virtual void SetDPIScale() { + if (DesignMode) return; if (!IsScaled) { this.SetDPIScaleFont(); @@ -341,10 +345,26 @@ namespace Sunny.UI } } + [Browsable(false), DefaultValue(typeof(Size), "0, 0")] + public ControlScaleInfo DesignedRect { get; private set; } + protected override void OnVisibleChanged(EventArgs e) { base.OnVisibleChanged(e); - if (AutoScaleMode == AutoScaleMode.Font) AutoScaleMode = AutoScaleMode.None; + if (AutoScaleMode == AutoScaleMode.Font) + { + 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 df87e847..bcb9d1f1 100644 --- a/SunnyUI/Forms/UIForm.cs +++ b/SunnyUI/Forms/UIForm.cs @@ -82,6 +82,9 @@ namespace Sunny.UI titleForeColor = UIStyles.Blue.FormTitleForeColor; } + [DefaultValue(false), Category("SunnyUI"), Description("禁止控件跟随窗体缩放")] + public bool ForbidControlScale { get; set; } + [Browsable(false)] public bool IsScaled { get; private set; } @@ -112,6 +115,27 @@ namespace Sunny.UI } } + [DefaultValue(typeof(Size), "0, 0")] + [Description("设计界面大小"), Category("SunnyUI")] + public ControlScaleInfo DesignedRect { get; private set; } + + private void SetControlScale() + { + if (ForbidControlScale) return; + if (!UIStyles.DPIScale || !UIStyles.ControlScale) return; + if (DesignedRect.Width == 0 || DesignedRect.Height == 0) return; + if (Width == 0 || Height == 0) return; + float scale = Math.Min(Width * 1.0f / DesignedRect.Width, Height * 1.0f / DesignedRect.Height); + if (scale.EqualsFloat(0)) return; + foreach (Control control in this.GetAllDPIScaleControls()) + { + if (control is IStyleInterface) + { + UIDPIScale.SetControlScale(control, scale); + } + } + } + public void ResetDPIScale() { IsScaled = false; @@ -1220,6 +1244,7 @@ namespace Sunny.UI public void SetStyle(UIStyle style) { + if (DesignMode) return; this.SuspendLayout(); UIStyleHelper.SetChildUIStyle(this, style); @@ -1267,6 +1292,7 @@ namespace Sunny.UI protected override void OnSizeChanged(EventArgs e) { base.OnSizeChanged(e); + SetControlScale(); CalcSystemBoxPos(); if (isShow) @@ -1300,6 +1326,15 @@ namespace Sunny.UI SetRadius(); isShow = true; SetDPIScale(); + SetDesignedSize(); + } + + protected virtual void SetDesignedSize() + { + if (DesignedRect.Width == 0 && DesignedRect.Height == 0) + { + DesignedRect = new ControlScaleInfo(this); ; + } } /// @@ -1990,18 +2025,43 @@ namespace Sunny.UI private UIForm SetDefaultTabControl() { - if (MainTabControl == null) + List ctrls = this.GetControls(); + if (ctrls.Count == 1) { - List ctrls = this.GetControls(); - if (ctrls.Count == 1) MainTabControl = ctrls[0]; + if (MainTabControl == null) + { + MainTabControl = ctrls[0]; + } + + List Menus = this.GetControls(); + if (Menus.Count == 1 && Menus[0].TabControl == null) + { + Menus[0].TabControl = ctrls[0]; + } + + List Bars = this.GetControls(); + if (Bars.Count == 1 && Bars[0].TabControl == null) + { + Bars[0].TabControl = ctrls[0]; + } } return this; } - public virtual void SelectPage(int pageIndex) => SetDefaultTabControl().MainTabControl?.SelectPage(pageIndex); + public virtual bool SelectPage(int pageIndex) + { + SetDefaultTabControl(); + if (MainTabControl == null) return false; + return MainTabControl.SelectPage(pageIndex); + } - public virtual void SelectPage(Guid guid) => SetDefaultTabControl().MainTabControl?.SelectPage(guid); + public virtual bool SelectPage(Guid guid) + { + SetDefaultTabControl(); + if (MainTabControl == null) return false; + return MainTabControl.SelectPage(guid); + } public bool RemovePage(int pageIndex) => MainTabControl?.RemovePage(pageIndex) ?? false; diff --git a/SunnyUI/Frames/IFrame.cs b/SunnyUI/Frames/IFrame.cs index 68531281..27cce8e9 100644 --- a/SunnyUI/Frames/IFrame.cs +++ b/SunnyUI/Frames/IFrame.cs @@ -34,9 +34,9 @@ namespace Sunny.UI UIPage AddPage(UIPage page); - void SelectPage(int pageIndex); + bool SelectPage(int pageIndex); - void SelectPage(Guid guid); + bool SelectPage(Guid guid); UIPage GetPage(int pageIndex); @@ -57,7 +57,9 @@ namespace Sunny.UI bool SetParamToPage(int toPageIndex, int fromPageIndex, params object[] objects); bool SetParamToPage(Guid toPageGuid, Guid fromPageGuid, params object[] objects); + void Init(); + void Final(); T GetPage() where T : UIPage; diff --git a/SunnyUI/Frames/UIAsideMainFrame.cs b/SunnyUI/Frames/UIAsideMainFrame.cs index 250bfbb6..c9b49039 100644 --- a/SunnyUI/Frames/UIAsideMainFrame.cs +++ b/SunnyUI/Frames/UIAsideMainFrame.cs @@ -35,11 +35,12 @@ namespace Sunny.UI Aside.TabControl = MainTabControl; } - public override void SelectPage(int pageIndex) + public override bool SelectPage(int pageIndex) { - base.SelectPage(pageIndex); + bool result = base.SelectPage(pageIndex); TreeNode node = Aside.GetTreeNode(pageIndex); if (node != null) Aside.SelectedNode = node; + return result; } } } \ No newline at end of file diff --git a/SunnyUI/Frames/UIHeaderAsideMainFrame.cs b/SunnyUI/Frames/UIHeaderAsideMainFrame.cs index 0712964d..ed2f9fa7 100644 --- a/SunnyUI/Frames/UIHeaderAsideMainFrame.cs +++ b/SunnyUI/Frames/UIHeaderAsideMainFrame.cs @@ -37,11 +37,12 @@ namespace Sunny.UI Aside.TabControl = MainTabControl; } - public override void SelectPage(int pageIndex) + public override bool SelectPage(int pageIndex) { - base.SelectPage(pageIndex); + bool result = base.SelectPage(pageIndex); TreeNode node = Aside.GetTreeNode(pageIndex); if (node != null) Aside.SelectedNode = node; + return result; } } } \ No newline at end of file diff --git a/SunnyUI/Frames/UIPage.cs b/SunnyUI/Frames/UIPage.cs index aa65da13..e8fb642c 100644 --- a/SunnyUI/Frames/UIPage.cs +++ b/SunnyUI/Frames/UIPage.cs @@ -76,11 +76,33 @@ namespace Sunny.UI titleForeColor = UIStyles.Blue.PageTitleForeColor; } + [DefaultValue(false), Category("SunnyUI"), Description("禁止控件跟随窗体缩放")] + public bool ForbidControlScale { get; set; } + + [Browsable(false), DefaultValue(typeof(Size), "0, 0")] + 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); + } + } + [Browsable(false)] public bool IsScaled { get; private set; } public void SetDPIScale() { + if (DesignMode) return; + if (!IsScaled) { this.SetDPIScaleFont(); diff --git a/SunnyUI/Style/UIDPIScale.cs b/SunnyUI/Style/UIDPIScale.cs index b32ecdc6..b72a9368 100644 --- a/SunnyUI/Style/UIDPIScale.cs +++ b/SunnyUI/Style/UIDPIScale.cs @@ -105,5 +105,87 @@ namespace Sunny.UI return list; } + + private static int Calc(int size, float scale) + { + return (int)(size * scale + 0.5); + } + + internal static void SetControlScale(Control control, float scale) + { + if (scale.EqualsFloat(0)) return; + + if (control is IStyleInterface ctrl) + { + if (ctrl.ForbidControlScale) + { + 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; + } + } + } } } diff --git a/SunnyUI/Style/UIStyle.cs b/SunnyUI/Style/UIStyle.cs index d839a679..7935ed24 100644 --- a/SunnyUI/Style/UIStyle.cs +++ b/SunnyUI/Style/UIStyle.cs @@ -23,8 +23,6 @@ * 2021-10-16: V3.0.8 增加系统DPI缩放自适应 ******************************************************************************/ -using System; -using System.Collections.Concurrent; using System.Collections.Generic; using System.Drawing; using System.Reflection; @@ -61,6 +59,53 @@ 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(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; + } + } + } } /// @@ -147,299 +192,6 @@ namespace Sunny.UI Colorful = 999 } - /// - /// 主题样式管理类 - /// - public static class UIStyles - { - public static bool DPIScale { get; set; } - - public static float FontSize { get; set; } = 12; - - public static List PopularStyles() - { - List styles = new List(); - foreach (UIStyle style in Enum.GetValues(typeof(UIStyle))) - { - if (style.Value() >= UIStyle.Blue.Value() && style.Value() < UIStyle.Colorful.Value()) - { - styles.Add(style); - } - } - - return styles; - } - - /// - /// 自定义 - /// - private static readonly UIBaseStyle Custom = new UICustomStyle(); - - /// - /// 蓝 - /// - public static readonly UIBaseStyle Blue = new UIBlueStyle(); - - /// - /// 橙 - /// - public static readonly UIBaseStyle Orange = new UIOrangeStyle(); - - /// - /// 灰 - /// - public static readonly UIBaseStyle Gray = new UIGrayStyle(); - - /// - /// 绿 - /// - public static readonly UIBaseStyle Green = new UIGreenStyle(); - - /// - /// 红 - /// - public static readonly UIBaseStyle Red = new UIRedStyle(); - - /// - /// 深蓝 - /// - public static readonly UIBaseStyle DarkBlue = new UIDarkBlueStyle(); - - /// - /// 黑 - /// - public static readonly UIBaseStyle Black = new UIBlackStyle(); - - /// - /// 紫 - /// - public static readonly UIBaseStyle Purple = new UIPurpleStyle(); - - /// - /// 多彩 - /// - private static readonly UIColorfulStyle Colorful = new UIColorfulStyle(); - - public static void InitColorful(Color styleColor, Color foreColor) - { - Colorful.Init(styleColor, foreColor); - Style = UIStyle.Colorful; - SetStyle(Style); - } - - private static readonly ConcurrentDictionary Styles = new ConcurrentDictionary(); - private static readonly ConcurrentDictionary Forms = new ConcurrentDictionary(); - private static readonly ConcurrentDictionary Pages = new ConcurrentDictionary(); - - /// - /// 菜单颜色集合 - /// - public static readonly ConcurrentDictionary MenuColors = new ConcurrentDictionary(); - - static UIStyles() - { - AddStyle(Custom); - AddStyle(Blue); - AddStyle(Orange); - AddStyle(Gray); - AddStyle(Green); - AddStyle(Red); - AddStyle(DarkBlue); - - AddStyle(new UIBaseStyle().Init(UIColor.LayuiGreen, UIStyle.LayuiGreen, Color.White, UIFontColor.Primary)); - AddStyle(new UIBaseStyle().Init(UIColor.LayuiRed, UIStyle.LayuiRed, Color.White, UIFontColor.Primary)); - AddStyle(new UIBaseStyle().Init(UIColor.LayuiOrange, UIStyle.LayuiOrange, Color.White, UIFontColor.Primary)); - - AddStyle(Black); - AddStyle(Purple); - - AddStyle(Colorful); - - MenuColors.TryAdd(UIMenuStyle.Custom, new UIMenuCustomColor()); - MenuColors.TryAdd(UIMenuStyle.Black, new UIMenuBlackColor()); - MenuColors.TryAdd(UIMenuStyle.White, new UIMenuWhiteColor()); - } - - /// - /// 主题样式整数值 - /// - /// 主题样式 - /// 整数值 - public static int Value(this UIStyle style) - { - return (int)style; - } - - /// - /// 注册窗体 - /// - /// GUID - /// 窗体 - public static bool Register(Guid guid, UIForm form) - { - if (!Forms.ContainsKey(guid)) - { - Forms.TryAddOrUpdate(guid, form); - return true; - } - - return false; - } - - /// - /// 注册页面 - /// - /// GUID - /// 页面 - public static bool Register(Guid guid, UIPage page) - { - if (!Pages.ContainsKey(guid)) - { - Pages.TryAddOrUpdate(guid, page); - return true; - } - - return false; - } - - /// - /// 注册窗体 - /// - /// 窗体 - public static bool Register(this UIForm form) - { - if (!Forms.ContainsKey(form.Guid)) - { - Forms.TryAddOrUpdate(form.Guid, form); - return true; - } - - return false; - } - - /// - /// 注册页面 - /// - /// 页面 - public static bool Register(this UIPage page) - { - if (!Pages.ContainsKey(page.Guid)) - { - Pages.TryAddOrUpdate(page.Guid, page); - return true; - } - - return false; - } - - /// - /// 反注册窗体 - /// - /// 窗体 - public static void UnRegister(this UIForm form) - { - Forms.TryRemove(form.Guid, out _); - } - - /// - /// 反注册页面 - /// - /// 页面 - public static void UnRegister(this UIPage page) - { - Pages.TryRemove(page.Guid, out _); - } - - /// - /// 反注册窗体、页面 - /// - /// GUID - public static void UnRegister(Guid guid) - { - if (Forms.ContainsKey(guid)) - Forms.TryRemove(guid, out _); - - if (Pages.ContainsKey(guid)) - Pages.TryRemove(guid, out _); - - } - - /// - /// 获取主题样式 - /// - /// 主题样式名称 - /// 主题样式 - public static UIBaseStyle GetStyleColor(UIStyle style) - { - if (Styles.ContainsKey(style)) - { - return Styles[style]; - } - - Style = UIStyle.Blue; - return Styles[Style]; - } - - public static UIBaseStyle ActiveStyleColor => GetStyleColor(Style); - - private static void AddStyle(UIBaseStyle uiColor) - { - if (Styles.ContainsKey(uiColor.Name)) - { - MessageBox.Show(uiColor.Name + " is already exist."); - } - - Styles.TryAdd(uiColor.Name, uiColor); - } - - /// - /// 主题样式 - /// - public static UIStyle Style { get; private set; } = UIStyle.Blue; - - /// - /// 设置主题样式 - /// - /// 主题样式 - public static void SetStyle(UIStyle style) - { - Style = style; - - foreach (var form in Forms.Values) - { - form.Style = style; - } - - foreach (var page in Pages.Values) - { - page.Style = style; - } - } - - public static void SetDPIScale() - { - foreach (var form in Forms.Values) - { - if (!UIDPIScale.DPIScaleIsOne()) - form.SetDPIScale(); - } - - foreach (var page in Pages.Values) - { - if (!UIDPIScale.DPIScaleIsOne()) - page.SetDPIScale(); - } - } - - public static void Translate() - { - foreach (var form in Forms.Values) - { - form.Translate(); - } - } - } - /// /// 主题颜色 /// diff --git a/SunnyUI/Style/UIStyleManager.cs b/SunnyUI/Style/UIStyleManager.cs index 9973f559..b6e1037c 100644 --- a/SunnyUI/Style/UIStyleManager.cs +++ b/SunnyUI/Style/UIStyleManager.cs @@ -85,6 +85,12 @@ namespace Sunny.UI set => UIStyles.FontSize = value; } + public bool ControlScale + { + get => UIStyles.ControlScale; + set => UIStyles.ControlScale = value; + } + /// /// 版本 /// diff --git a/SunnyUI/Style/UIStyles.cs b/SunnyUI/Style/UIStyles.cs new file mode 100644 index 00000000..587c1e04 --- /dev/null +++ b/SunnyUI/Style/UIStyles.cs @@ -0,0 +1,342 @@ +/****************************************************************************** + * SunnyUI 开源控件库、工具类库、扩展类库、多页面开发框架。 + * CopyRight (C) 2012-2022 ShenYongHua(沈永华). + * QQ群:56829229 QQ:17612584 EMail:SunnyUI@QQ.Com + * + * Blog: https://www.cnblogs.com/yhuse + * Gitee: https://gitee.com/yhuse/SunnyUI + * GitHub: https://github.com/yhuse/SunnyUI + * + * SunnyUI.dll can be used for free under the GPL-3.0 license. + * If you use this code, please keep this note. + * 如果您使用此代码,请保留此说明。 + ****************************************************************************** + * 文件名称: UIStyles.cs + * 文件说明: 主题样式管理类 + * 当前版本: V3.1 + * 创建日期: 2020-01-01 + * + * 2020-01-01: V2.2.0 增加文件说明 + * 2021-07-12: V3.0.5 增加紫色主题 + * 2021-07-18: V3.0.5 增加多彩主题,以颜色深色,文字白色为主 + * 2021-09-24: V3.0.7 修改默认字体的GdiCharSet + * 2021-10-16: V3.0.8 增加系统DPI缩放自适应 +******************************************************************************/ + +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Drawing; +using System.Windows.Forms; + +namespace Sunny.UI +{ + /// + /// 主题样式管理类 + /// + public static class UIStyles + { + public static bool DPIScale { get; set; } + + public static bool ControlScale { get; set; } + + public static float FontSize { get; set; } = 12; + + public static List PopularStyles() + { + List styles = new List(); + foreach (UIStyle style in Enum.GetValues(typeof(UIStyle))) + { + if (style.Value() >= UIStyle.Blue.Value() && style.Value() < UIStyle.Colorful.Value()) + { + styles.Add(style); + } + } + + return styles; + } + + /// + /// 自定义 + /// + private static readonly UIBaseStyle Custom = new UICustomStyle(); + + /// + /// 蓝 + /// + public static readonly UIBaseStyle Blue = new UIBlueStyle(); + + /// + /// 橙 + /// + public static readonly UIBaseStyle Orange = new UIOrangeStyle(); + + /// + /// 灰 + /// + public static readonly UIBaseStyle Gray = new UIGrayStyle(); + + /// + /// 绿 + /// + public static readonly UIBaseStyle Green = new UIGreenStyle(); + + /// + /// 红 + /// + public static readonly UIBaseStyle Red = new UIRedStyle(); + + /// + /// 深蓝 + /// + public static readonly UIBaseStyle DarkBlue = new UIDarkBlueStyle(); + + /// + /// 黑 + /// + public static readonly UIBaseStyle Black = new UIBlackStyle(); + + /// + /// 紫 + /// + public static readonly UIBaseStyle Purple = new UIPurpleStyle(); + + /// + /// 多彩 + /// + private static readonly UIColorfulStyle Colorful = new UIColorfulStyle(); + + public static void InitColorful(Color styleColor, Color foreColor) + { + Colorful.Init(styleColor, foreColor); + Style = UIStyle.Colorful; + SetStyle(Style); + } + + private static readonly ConcurrentDictionary Styles = new ConcurrentDictionary(); + private static readonly ConcurrentDictionary Forms = new ConcurrentDictionary(); + private static readonly ConcurrentDictionary Pages = new ConcurrentDictionary(); + + /// + /// 菜单颜色集合 + /// + public static readonly ConcurrentDictionary MenuColors = new ConcurrentDictionary(); + + static UIStyles() + { + AddStyle(Custom); + AddStyle(Blue); + AddStyle(Orange); + AddStyle(Gray); + AddStyle(Green); + AddStyle(Red); + AddStyle(DarkBlue); + + AddStyle(new UIBaseStyle().Init(UIColor.LayuiGreen, UIStyle.LayuiGreen, Color.White, UIFontColor.Primary)); + AddStyle(new UIBaseStyle().Init(UIColor.LayuiRed, UIStyle.LayuiRed, Color.White, UIFontColor.Primary)); + AddStyle(new UIBaseStyle().Init(UIColor.LayuiOrange, UIStyle.LayuiOrange, Color.White, UIFontColor.Primary)); + + AddStyle(Black); + AddStyle(Purple); + + AddStyle(Colorful); + + MenuColors.TryAdd(UIMenuStyle.Custom, new UIMenuCustomColor()); + MenuColors.TryAdd(UIMenuStyle.Black, new UIMenuBlackColor()); + MenuColors.TryAdd(UIMenuStyle.White, new UIMenuWhiteColor()); + } + + /// + /// 主题样式整数值 + /// + /// 主题样式 + /// 整数值 + public static int Value(this UIStyle style) + { + return (int)style; + } + + /// + /// 注册窗体 + /// + /// GUID + /// 窗体 + public static bool Register(Guid guid, UIForm form) + { + if (!Forms.ContainsKey(guid)) + { + Forms.TryAddOrUpdate(guid, form); + return true; + } + + return false; + } + + /// + /// 注册页面 + /// + /// GUID + /// 页面 + public static bool Register(Guid guid, UIPage page) + { + if (!Pages.ContainsKey(guid)) + { + Pages.TryAddOrUpdate(guid, page); + return true; + } + + return false; + } + + /// + /// 注册窗体 + /// + /// 窗体 + public static bool Register(this UIForm form) + { + if (!Forms.ContainsKey(form.Guid)) + { + Forms.TryAddOrUpdate(form.Guid, form); + return true; + } + + return false; + } + + /// + /// 注册页面 + /// + /// 页面 + public static bool Register(this UIPage page) + { + if (!Pages.ContainsKey(page.Guid)) + { + Pages.TryAddOrUpdate(page.Guid, page); + return true; + } + + return false; + } + + public static List GetPages() where T : UIPage + { + List result = new List(); + foreach (var page in Pages) + { + if (page is T pg) + result.Add(pg); + } + + return result; + } + + /// + /// 反注册窗体 + /// + /// 窗体 + public static void UnRegister(this UIForm form) + { + Forms.TryRemove(form.Guid, out _); + } + + /// + /// 反注册页面 + /// + /// 页面 + public static void UnRegister(this UIPage page) + { + Pages.TryRemove(page.Guid, out _); + } + + /// + /// 反注册窗体、页面 + /// + /// GUID + public static void UnRegister(Guid guid) + { + if (Forms.ContainsKey(guid)) + Forms.TryRemove(guid, out _); + + if (Pages.ContainsKey(guid)) + Pages.TryRemove(guid, out _); + + } + + /// + /// 获取主题样式 + /// + /// 主题样式名称 + /// 主题样式 + public static UIBaseStyle GetStyleColor(UIStyle style) + { + if (Styles.ContainsKey(style)) + { + return Styles[style]; + } + + Style = UIStyle.Blue; + return Styles[Style]; + } + + public static UIBaseStyle ActiveStyleColor => GetStyleColor(Style); + + private static void AddStyle(UIBaseStyle uiColor) + { + if (Styles.ContainsKey(uiColor.Name)) + { + MessageBox.Show(uiColor.Name + " is already exist."); + } + + Styles.TryAdd(uiColor.Name, uiColor); + } + + /// + /// 主题样式 + /// + public static UIStyle Style { get; private set; } = UIStyle.Blue; + + /// + /// 设置主题样式 + /// + /// 主题样式 + public static void SetStyle(UIStyle style) + { + Style = style; + + foreach (var form in Forms.Values) + { + form.Style = style; + } + + foreach (var page in Pages.Values) + { + page.Style = style; + } + } + + public static void SetDPIScale() + { + if (!DPIScale) return; + + foreach (var form in Forms.Values) + { + if (!UIDPIScale.DPIScaleIsOne()) + form.SetDPIScale(); + } + + foreach (var page in Pages.Values) + { + if (!UIDPIScale.DPIScaleIsOne()) + page.SetDPIScale(); + } + } + + public static void Translate() + { + foreach (var form in Forms.Values) + { + form.Translate(); + } + } + } +}