* 源码兼容VS2019编译,在Nuget发布时增加.Net6目标编译,.Net6应用从Nuget引用。

This commit is contained in:
Sunny 2022-01-09 11:38:14 +08:00
parent 7bebb67433
commit 4c91c0a976
7 changed files with 30 additions and 21 deletions

Binary file not shown.

Binary file not shown.

View File

@ -19,7 +19,7 @@ namespace Sunny.UI.Demo.Properties {
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /str 作为命令选项),或重新生成 VS 项目。 // (以 /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.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources { internal class Resources {
@ -271,7 +271,7 @@ namespace Sunny.UI.Demo.Properties {
} }
/// <summary> /// <summary>
/// 查找类似 20220105 的本地化字符串。 /// 查找类似 20220109 的本地化字符串。
/// </summary> /// </summary>
internal static string BuildDate { internal static string BuildDate {
get { get {

View File

@ -155,7 +155,7 @@
<value>..\Resources\brescia.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\brescia.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="BuildDate" xml:space="preserve"> <data name="BuildDate" xml:space="preserve">
<value>20220105</value> <value>20220109</value>
</data> </data>
<data name="ChartDarkStyle" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="ChartDarkStyle" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ChartDarkStyle.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\ChartDarkStyle.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>

View File

@ -507,7 +507,7 @@ namespace Sunny.UI
private void CalcEditHeight() private void CalcEditHeight()
{ {
TextBox edt = new(); TextBox edt = new TextBox();
edt.Font = edit.Font.DPIScaleFont(); edt.Font = edit.Font.DPIScaleFont();
MinHeight = edt.PreferredHeight; MinHeight = edt.PreferredHeight;
edt.BorderStyle = BorderStyle.None; edt.BorderStyle = BorderStyle.None;

View File

@ -27,6 +27,11 @@ namespace Sunny.UI
{ {
public static class UIDPIScale public static class UIDPIScale
{ {
public static float DPIScale()
{
return GDI.Graphics().DpiX / 96.0f;
}
public static float DPIScale(this Control control) public static float DPIScale(this Control control)
{ {
try try
@ -57,9 +62,8 @@ namespace Sunny.UI
public static float DPIScaleFontSize(this float fontSize) public static float DPIScaleFontSize(this float fontSize)
{ {
using Control control = new();
if (UIStyles.DPIScale) if (UIStyles.DPIScale)
return fontSize / control.DPIScale(); return fontSize / DPIScale();
else else
return fontSize; return fontSize;
} }
@ -69,6 +73,24 @@ namespace Sunny.UI
return control.DPIScaleFont(font, font.Size); 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) public static Font DPIScaleFont(this Control control, Font font, float fontSize)
{ {
if (UIStyles.DPIScale) 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) public static void SetDPIScaleFont(this Control control)
{ {
if (!UIStyles.DPIScale) return; if (!UIStyles.DPIScale) return;
if (!control.DPIScale().EqualsFloat(1)) if (!DPIScale().EqualsFloat(1))
{ {
if (control is IStyleInterface ctrl) if (control is IStyleInterface ctrl)
{ {

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net6.0-windows;net5.0-windows;net472;net40</TargetFrameworks> <TargetFrameworks>net5.0-windows;net472;net40</TargetFrameworks>
<LangVersion>9.0</LangVersion> <LangVersion>9.0</LangVersion>
<ProjectGuid>{AB1CB247-E20B-4CBE-B269-570ADDD96C53}</ProjectGuid> <ProjectGuid>{AB1CB247-E20B-4CBE-B269-570ADDD96C53}</ProjectGuid>
<UseWindowsForms>true</UseWindowsForms> <UseWindowsForms>true</UseWindowsForms>