C#界面字体突然变大的原因:
在.csproj文件里: 加了这一句 <Reference Include="PresentationFramework" />
进一步研究:
在APP.manifest里加入:
<!-- 指示该应用程序可以感知 DPI 且 Windows 在 DPI 较高时将不会对其进行
自动缩放。Windows Presentation Foundation (WPF)应用程序自动感知 DPI,无需
选择加入。选择加入此设置的 Windows 窗体应用程序(目标设定为 .NET Framework 4.6 )还应
在其 app.config 中将 "EnableWindowsFormsHighDpiAutoResizing" 设置设置为 "true"。-->
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
</windowsSettings>
</application>
也可以实现相同的效果,且不影响界面布局,详见:
C#Winform之高分辨率下的窗体显示模糊_淡定vs冷漠的博客-CSDN博客
或者用代码实现:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Josher.ABScanner.Forms;
using VersionCtrl;
namespace Josher.ABScanner
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
if (Environment.OSVersion.Version.Major >= 6)
{
SetProcessDPIAware();
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//语言设置
LanguageStr.refreshLanguage();
Application.Run(new FrmLogin());
}
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool SetProcessDPIAware();
}
}
微软官方的建议是: