diff --git a/Bin/net40/SunnyUI.dll b/Bin/net40/SunnyUI.dll index 11b95c75..55034133 100644 Binary files a/Bin/net40/SunnyUI.dll and b/Bin/net40/SunnyUI.dll differ diff --git a/SunnyUI/Charts/UIChart.cs b/SunnyUI/Charts/UIChart.cs index 1e4e60ab..9386fed0 100644 --- a/SunnyUI/Charts/UIChart.cs +++ b/SunnyUI/Charts/UIChart.cs @@ -198,7 +198,7 @@ namespace Sunny.UI { float size = SubFont != null ? SubFont.Size : UIFontColor.SubFontSize; - if (tmpFont == null || !tmpFont.Size.EqualsFloat(size / this.DPIScale())) + if (tmpFont == null || !tmpFont.Size.EqualsFloat(size / UIDPIScale.DPIScale())) { tmpFont?.Dispose(); tmpFont = this.DPIScaleFont(Font, size); @@ -216,7 +216,7 @@ namespace Sunny.UI { float size = LegendFont != null ? LegendFont.Size : UIFontColor.SubFontSize; - if (tmpLegendFont == null || !tmpLegendFont.Size.EqualsFloat(size / this.DPIScale())) + if (tmpLegendFont == null || !tmpLegendFont.Size.EqualsFloat(size / UIDPIScale.DPIScale())) { tmpLegendFont?.Dispose(); tmpLegendFont = this.DPIScaleFont(Font, size); diff --git a/SunnyUI/Controls/DropItem/UIDateItem.cs b/SunnyUI/Controls/DropItem/UIDateItem.cs index 6c7906b6..cbeb96c5 100644 --- a/SunnyUI/Controls/DropItem/UIDateItem.cs +++ b/SunnyUI/Controls/DropItem/UIDateItem.cs @@ -728,7 +728,7 @@ namespace Sunny.UI if (ShowToday) { - using (Font SubFont = new Font("微软雅黑", 10.5f / this.DPIScale())) + using (Font SubFont = new Font("微软雅黑", 10.5f / UIDPIScale.DPIScale())) { e.Graphics.FillRectangle(p3.FillColor, p3.Width - width * 4 + 1, p3.Height - height + 1, width * 4 - 2, height - 2); e.Graphics.FillRoundRectangle(PrimaryColor, new Rectangle(p3.Width - width * 4 + 6, p3.Height - height + 3, 8, height - 10), 3); diff --git a/SunnyUI/Controls/DropItem/UIDateTimeItem.cs b/SunnyUI/Controls/DropItem/UIDateTimeItem.cs index f4a2cd52..9500b08a 100644 --- a/SunnyUI/Controls/DropItem/UIDateTimeItem.cs +++ b/SunnyUI/Controls/DropItem/UIDateTimeItem.cs @@ -1279,7 +1279,7 @@ namespace Sunny.UI if (ShowToday) { - using (Font SubFont = new Font("微软雅黑", 10.5f / this.DPIScale())) + using (Font SubFont = new Font("微软雅黑", 10.5f / UIDPIScale.DPIScale())) { e.Graphics.FillRectangle(p3.FillColor, p3.Width - width * 4 + 1, p3.Height - height + 1, width * 4 - 2, height - 2); e.Graphics.FillRoundRectangle(PrimaryColor, new Rectangle((int)(p3.Width - width * 4 + 6), p3.Height - height + 3, 8, height - 10), 3); diff --git a/SunnyUI/Forms/UIForm.cs b/SunnyUI/Forms/UIForm.cs index ef6297d6..55cc4c29 100644 --- a/SunnyUI/Forms/UIForm.cs +++ b/SunnyUI/Forms/UIForm.cs @@ -90,7 +90,7 @@ namespace Sunny.UI { this.SetDPIScaleFont(); - if (!this.DPIScale().Equals(1)) + if (!UIDPIScale.DPIScaleIsOne()) { TitleFont = this.DPIScaleFont(TitleFont); } diff --git a/SunnyUI/Frames/UIPage.cs b/SunnyUI/Frames/UIPage.cs index fb762dc2..feca78c8 100644 --- a/SunnyUI/Frames/UIPage.cs +++ b/SunnyUI/Frames/UIPage.cs @@ -83,7 +83,7 @@ namespace Sunny.UI if (!IsScaled) { this.SetDPIScaleFont(); - if (!this.DPIScale().Equals(1)) + if (!UIDPIScale.DPIScaleIsOne()) { this.TitleFont = this.DPIScaleFont(this.TitleFont); } diff --git a/SunnyUI/Style/UIDPIScale.cs b/SunnyUI/Style/UIDPIScale.cs index 411e3234..05ef635c 100644 --- a/SunnyUI/Style/UIDPIScale.cs +++ b/SunnyUI/Style/UIDPIScale.cs @@ -32,25 +32,15 @@ namespace Sunny.UI return GDI.Graphics().DpiX / 96.0f; } - public static float DPIScale(this Control control) + public static bool DPIScaleIsOne() { - try - { - if (control != null) - return control.CreateGraphics().DpiX / 96.0f; - else - return GDI.Graphics().DpiX / 96.0f; - } - catch - { - return 1; - } + return DPIScale().EqualsFloat(1); } public static float DPIScaleFontSize(this Control control, Font font) { if (UIStyles.DPIScale) - return font.Size / control.DPIScale(); + return font.Size / DPIScale(); else return font.Size; } @@ -96,9 +86,9 @@ namespace Sunny.UI if (UIStyles.DPIScale) { if (font.GdiCharSet == 134) - return new Font(font.FontFamily, fontSize / control.DPIScale(), font.Style, font.Unit, font.GdiCharSet); + return new Font(font.FontFamily, fontSize / DPIScale(), font.Style, font.Unit, font.GdiCharSet); else - return new Font(font.FontFamily, fontSize / control.DPIScale()); + return new Font(font.FontFamily, fontSize / DPIScale()); } else { @@ -112,7 +102,7 @@ namespace Sunny.UI public static void SetDPIScaleFont(this Control control) { if (!UIStyles.DPIScale) return; - if (!DPIScale().EqualsFloat(1)) + if (!UIDPIScale.DPIScaleIsOne()) { if (control is IStyleInterface ctrl) { diff --git a/SunnyUI/Style/UIStyle.cs b/SunnyUI/Style/UIStyle.cs index 8be62d94..1303347c 100644 --- a/SunnyUI/Style/UIStyle.cs +++ b/SunnyUI/Style/UIStyle.cs @@ -415,13 +415,13 @@ namespace Sunny.UI { foreach (var form in Forms.Values) { - if (!form.DPIScale().EqualsFloat(1)) + if (!UIDPIScale.DPIScaleIsOne()) form.SetDPIScale(); } foreach (var page in Pages.Values) { - if (!page.DPIScale().EqualsFloat(1)) + if (!UIDPIScale.DPIScaleIsOne()) page.SetDPIScale(); } }