zoukankan      html  css  js  c++  java
  • Winform 在高分变率显示器中窗体变模糊配置方式

       我们知道  Winform 前身与 XP 系统 同一时代出生 , 那时候显示器还是LCD 和 大头机 ,显示器普遍  96 DPI  。 随着显示器质量改善,2K 屏, 4K屏普及,DPI 达  192 甚至更高。  原来winform 程序在 96 dpi 环境开发编译 程序 , 运行完好,在  192  dpi  下,布局可能会错乱 , 或者字看起来小很多 , 字体与边框线条缩放规则不协调等,因此微软提供配置 支持高低 分辨率布局兼容 方式如下:

      1.  通过代码实现:

       

     static class Program
        {
            [System.Runtime.InteropServices.DllImport("user32.dll")]
            private static extern bool SetProcessDPIAware();
    
            /// <summary>
            /// 应用程序的主入口点。
            /// </summary>
            [STAThread]
            static void Main()
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
    
                if (Environment.OSVersion.Version.Major >= 6)
                    SetProcessDPIAware();
    
                Application.Run(new Form4());
            }
        }

    2. 通过配置文件实现:

        添加应用程序清单文件:

       

       同时 启用如下配置:

      <application xmlns="urn:schemas-microsoft-com:asm.v3">
        <windowsSettings>
          <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
        </windowsSettings>
      </application>

    app.config 中增加配置项:

      <appSettings>
        <add key="EnableWindowsFormsHighDpiAutoResizing" value= "true" />
      </appSettings>

     设置窗体模式:

    这样让操作系统自动处理软件缩放,支持高清显示。

       

  • 相关阅读:
    linux报错jar包时出现“Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for Manifest main attributes”
    重写ajax方法实现请求session过期时跳转登录页面
    C++学习之NVI
    C++学习之Pimpl
    C++学习之allocator
    C++ 强制类型转换
    C++中的volatile关键字
    C++强大背后
    C++学习之智能指针
    C++学习之异常
  • 原文地址:https://www.cnblogs.com/howtrace/p/13130474.html
Copyright © 2011-2022 走看看