diff --git a/Bin/net40/SunnyUI.Demo.exe b/Bin/net40/SunnyUI.Demo.exe
index 740d06cd..6e1c29cb 100644
Binary files a/Bin/net40/SunnyUI.Demo.exe and b/Bin/net40/SunnyUI.Demo.exe differ
diff --git a/Bin/net40/SunnyUI.dll b/Bin/net40/SunnyUI.dll
index 0e98f19c..c83ab165 100644
Binary files a/Bin/net40/SunnyUI.dll and b/Bin/net40/SunnyUI.dll differ
diff --git a/SunnyUI.Demo/Properties/Resources.Designer.cs b/SunnyUI.Demo/Properties/Resources.Designer.cs
index 8ada9c82..01908b80 100644
--- a/SunnyUI.Demo/Properties/Resources.Designer.cs
+++ b/SunnyUI.Demo/Properties/Resources.Designer.cs
@@ -19,7 +19,7 @@ namespace Sunny.UI.Demo.Properties {
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /str 作为命令选项),或重新生成 VS 项目。
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
@@ -271,7 +271,7 @@ namespace Sunny.UI.Demo.Properties {
}
///
- /// 查找类似 20220105 的本地化字符串。
+ /// 查找类似 20220109 的本地化字符串。
///
internal static string BuildDate {
get {
diff --git a/SunnyUI.Demo/Properties/Resources.resx b/SunnyUI.Demo/Properties/Resources.resx
index 17a09aa9..7c67682a 100644
--- a/SunnyUI.Demo/Properties/Resources.resx
+++ b/SunnyUI.Demo/Properties/Resources.resx
@@ -155,7 +155,7 @@
..\Resources\brescia.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
- 20220105
+ 20220109
..\Resources\ChartDarkStyle.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
diff --git a/SunnyUI/Controls/UITextBox.cs b/SunnyUI/Controls/UITextBox.cs
index 871a3dff..0dea5400 100644
--- a/SunnyUI/Controls/UITextBox.cs
+++ b/SunnyUI/Controls/UITextBox.cs
@@ -507,7 +507,7 @@ namespace Sunny.UI
private void CalcEditHeight()
{
- TextBox edt = new();
+ TextBox edt = new TextBox();
edt.Font = edit.Font.DPIScaleFont();
MinHeight = edt.PreferredHeight;
edt.BorderStyle = BorderStyle.None;
diff --git a/SunnyUI/Style/UIDPIScale.cs b/SunnyUI/Style/UIDPIScale.cs
index b08c0f3b..411e3234 100644
--- a/SunnyUI/Style/UIDPIScale.cs
+++ b/SunnyUI/Style/UIDPIScale.cs
@@ -27,6 +27,11 @@ namespace Sunny.UI
{
public static class UIDPIScale
{
+ public static float DPIScale()
+ {
+ return GDI.Graphics().DpiX / 96.0f;
+ }
+
public static float DPIScale(this Control control)
{
try
@@ -57,9 +62,8 @@ namespace Sunny.UI
public static float DPIScaleFontSize(this float fontSize)
{
- using Control control = new();
if (UIStyles.DPIScale)
- return fontSize / control.DPIScale();
+ return fontSize / DPIScale();
else
return fontSize;
}
@@ -69,6 +73,24 @@ namespace Sunny.UI
return control.DPIScaleFont(font, font.Size);
}
+ public static Font DPIScaleFont(this Font font)
+ {
+ if (UIStyles.DPIScale)
+ {
+ if (font.GdiCharSet == 134)
+ return new Font(font.FontFamily, font.Size / DPIScale(), font.Style, font.Unit, font.GdiCharSet);
+ else
+ return new Font(font.FontFamily, font.Size / DPIScale());
+ }
+ else
+ {
+ if (font.GdiCharSet == 134)
+ return new Font(font.FontFamily, font.Size, font.Style, font.Unit, font.GdiCharSet);
+ else
+ return new Font(font.FontFamily, font.Size);
+ }
+ }
+
public static Font DPIScaleFont(this Control control, Font font, float fontSize)
{
if (UIStyles.DPIScale)
@@ -87,23 +109,10 @@ namespace Sunny.UI
}
}
- public static Font DPIScaleFont(this Font font)
- {
- if (UIStyles.DPIScale)
- {
- using Control control = new();
- return control.DPIScaleFont(font);
- }
- else
- {
- return font;
- }
- }
-
public static void SetDPIScaleFont(this Control control)
{
if (!UIStyles.DPIScale) return;
- if (!control.DPIScale().EqualsFloat(1))
+ if (!DPIScale().EqualsFloat(1))
{
if (control is IStyleInterface ctrl)
{
diff --git a/SunnyUI/SunnyUI.csproj b/SunnyUI/SunnyUI.csproj
index a259add5..6aa2da3c 100644
--- a/SunnyUI/SunnyUI.csproj
+++ b/SunnyUI/SunnyUI.csproj
@@ -1,7 +1,7 @@
- net6.0-windows;net5.0-windows;net472;net40
+ net5.0-windows;net472;net40
9.0
{AB1CB247-E20B-4CBE-B269-570ADDD96C53}
true