From 82f4074ba57cf6e9ea0544a920c3a18902915cf7 Mon Sep 17 00:00:00 2001 From: Sunny Date: Wed, 30 Aug 2023 11:18:57 +0800 Subject: [PATCH] =?UTF-8?q?*=20=E9=87=8D=E6=9E=84=E5=85=A8=E5=B1=80?= =?UTF-8?q?=E5=AD=97=E4=BD=93=E8=AE=BE=E7=BD=AE=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E4=BB=A5=E6=9C=9F=E5=8F=AF=E4=BB=A5=E5=9C=A8=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E8=BF=90=E8=A1=8C=E6=97=B6=E8=AE=BE=E7=BD=AE=E5=85=A8=E5=B1=80?= =?UTF-8?q?=E5=AD=97=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SunnyUI/Controls/UINavBar.cs | 2 +- SunnyUI/Forms/UINotifier.cs | 4 +-- SunnyUI/Style/UIDPIScale.cs | 47 +++++++++++++++++++----------------- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/SunnyUI/Controls/UINavBar.cs b/SunnyUI/Controls/UINavBar.cs index 6aa265da..254772a9 100644 --- a/SunnyUI/Controls/UINavBar.cs +++ b/SunnyUI/Controls/UINavBar.cs @@ -642,7 +642,7 @@ namespace Sunny.UI NavBarMenu.Style = UIStyles.Style; NavBarMenu.Items.Clear(); NavBarMenu.ImageList = ImageList; - NavBarMenu.Font = DropMenuFont.SetDPIScaleFont(DropMenuFont.Size); + NavBarMenu.Font = DropMenuFont; foreach (TreeNode node in Nodes[SelectedIndex].Nodes) { ToolStripMenuItem item = new ToolStripMenuItem(node.Text) { Tag = node }; diff --git a/SunnyUI/Forms/UINotifier.cs b/SunnyUI/Forms/UINotifier.cs index 1a74e3a6..74b4d3e0 100644 --- a/SunnyUI/Forms/UINotifier.cs +++ b/SunnyUI/Forms/UINotifier.cs @@ -35,8 +35,6 @@ using System.Linq; using System.Threading; using System.Windows.Forms; -#pragma warning disable 1591 - namespace Sunny.UI { public sealed partial class UINotifier : Form @@ -108,7 +106,7 @@ namespace Sunny.UI InApplication = insideMe; InitializeComponent(); - if (Notes.Count == 0) + if (Notes.IsEmpty) ID = 1; else ID = (short)(Notes.Keys.Max() + 1); // Set the Note ID diff --git a/SunnyUI/Style/UIDPIScale.cs b/SunnyUI/Style/UIDPIScale.cs index 40d7060f..387c5998 100644 --- a/SunnyUI/Style/UIDPIScale.cs +++ b/SunnyUI/Style/UIDPIScale.cs @@ -29,22 +29,24 @@ namespace Sunny.UI { private static float dpiScale = -1; - public static float DPIScale() + public static float DPIScale() => UIStyles.GlobalFont ? SystemDPIScale * 100.0f / UIStyles.GlobalFontScale : SystemDPIScale; + + private static float SystemDPIScale { - if (dpiScale < 0) + get { - using Bitmap bmp = new Bitmap(1, 1); - using Graphics g = bmp.Graphics(); - dpiScale = g.DpiX / 96.0f; + if (dpiScale < 0) + { + using Bitmap bmp = new Bitmap(1, 1); + using Graphics g = bmp.Graphics(); + dpiScale = g.DpiX / 96.0f; + } + + return dpiScale; } - - return UIStyles.GlobalFont ? dpiScale * 100.0f / UIStyles.GlobalFontScale : dpiScale; } - public static bool NeedSetDPIFont() - { - return UIStyles.DPIScale && (DPIScale() > 1 || UIStyles.GlobalFont); - } + public static bool NeedSetDPIFont() => UIStyles.DPIScale && (SystemDPIScale > 1 || UIStyles.GlobalFont); internal static Font DPIScaleFont(this Font font, float fontSize) { @@ -78,21 +80,22 @@ namespace Sunny.UI internal static List GetAllDPIScaleControls(this Control control) { var list = new List(); - foreach (Control con in control.Controls) + foreach (Control ctrl in control.Controls) { - if (con is IStyleInterface ctrl) list.Add(ctrl); + if (ctrl is IStyleInterface istyleCtrl) list.Add(istyleCtrl); - 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 (ctrl is UITextBox) continue; + if (ctrl is UIDropControl) continue; + if (ctrl is UIListBox) continue; + if (ctrl is UIImageListBox) continue; + if (ctrl is UIPagination) continue; + if (ctrl is UIRichTextBox) continue; + if (ctrl is UITreeView) continue; + if (ctrl is UITransfer) continue; - if (con.Controls.Count > 0) + if (ctrl.Controls.Count > 0) { - list.AddRange(GetAllDPIScaleControls(con)); + list.AddRange(GetAllDPIScaleControls(ctrl)); } }