C#界面字体突然变大的原因,C#高DPI支持,C#变模糊的问题

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();
    }
}
 

微软官方的建议是:

高 DPI 支持 - Windows Forms .NET Framework | Microsoft Docs

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值