惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

A
Arctic Wolf
博客园 - 聂微东
F
Fortinet All Blogs
云风的 BLOG
云风的 BLOG
小众软件
小众软件
V
Visual Studio Blog
博客园 - 三生石上(FineUI控件)
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Apple Machine Learning Research
Apple Machine Learning Research
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The Cloudflare Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The GitHub Blog
The GitHub Blog
Y
Y Combinator Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
L
LangChain Blog
A
About on SuperTechFans
阮一峰的网络日志
阮一峰的网络日志
I
Intezer
T
The Blog of Author Tim Ferriss
Security Latest
Security Latest
C
CXSECURITY Database RSS Feed - CXSecurity.com
Know Your Adversary
Know Your Adversary
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Palo Alto Networks Blog
Scott Helme
Scott Helme
S
Secure Thoughts
Spread Privacy
Spread Privacy
T
Threat Research - Cisco Blogs
Attack and Defense Labs
Attack and Defense Labs
P
Privacy & Cybersecurity Law Blog
O
OpenAI News
H
Heimdal Security Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Help Net Security
Help Net Security
C
Cyber Attacks, Cyber Crime and Cyber Security
Blog — PlanetScale
Blog — PlanetScale
GbyAI
GbyAI
G
Google Developers Blog
博客园 - Franky
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
K
Kaspersky official blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
T
Tor Project blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
Tenable Blog
Google Online Security Blog
Google Online Security Blog
PCI Perspectives
PCI Perspectives

博客园 - yhuse

MiniMax 权益码 Token Plan 套餐 9 折优惠,Token Plan 共建邀请计划 至2026.7.31 MiniMax 权益码 Token Plan 套餐 9 折优惠,Token Plan 共建邀请计划 至2026.7.31 MiniMax 权益码 Token Plan 套餐 9 折优惠,Token Plan 共建邀请计划 至2026.7.31 MiniMax 权益码 Token Plan 套餐 9 折优惠,至2026.6.30 MiniMax 权益码 Token Plan 套餐 9 折优惠,至2026.6.30 MiniMax 权益码 Token Plan 套餐 9 折优惠 MiniMax 权益码 Token Plan 套餐 9 折优惠 MiniMax 权益码 Token Plan 套餐 9 折优惠 WinForms 内置的公共系统级别编辑器 科技衰退,CodeProject.com 关闭了 DataView RowFilter Syntax [C#] .NET Standard 对 .NET 的每个实现的支持 NuGet 包版本引用 | Microsoft Docs C# Winform窗体继承过程中,TableLayoutPanel是不支持继承的 VS2022安装.NetFramework4.0目标包的方法 VS2022禁用全局using,禁用GlobalUsings.g.cs Ubuntu下libpcap安装步骤 Ubuntu 18.04 安装.net 5 .Net Framework各版本微软技术支持及到期日期 TargetFrameworks输出多版本类库,SDK 样式项目中的目标框架 [原创][开源] SunnyUI.Net 常见问题答疑 [原创][开源] SunnyUI.Net 开发日志:UIBarChart 坐标轴刻度取值算法 [原创][开源] SunnyUI.Net 主题 [原创][开源] SunnyUI.Net 字体图标 [原创][开源] SunnyUI.Net 国际化 [原创][开源] SunnyUI.Net 安装 [原创][开源] SunnyUI.Net 开发日志:UIListBox 增加跟随鼠标滑过高亮
[原创][开源]C# Winform DPI自适应方案,SunnyUI三步搞定
yhuse · 2022-04-22 · via 博客园 - yhuse

Winform窗体随着屏幕的DPI缩放,会引起窗体变形及字体变形。
SunnyUI的DPI缩放自适应方案目标为随着DPI缩放,窗体和字体均不变形,从而实现界面的美观。
主要有以下三步操作:

1、设置窗体和自定义用户控件的AutoScaleMode为None
实现目标:禁止窗体因为字体大小缩放变形
因为显示的高分屏,然后操作系统的设置了字体缩放引起的。窗体默认的AutoScaleMode = Font,控件会因为高分屏自动缩放。
解决方法:设置窗体、用户控件的AutoScaleMode = None
输入图片说明

2、设置app.manifest的dpiAware为true
实现目标:禁止窗体因为DPI缩放变形
选择项目属性,安全性
输入图片说明
选中 启用 ClickOnce 安全设置,再取消选中。
这时候项目的文件里就多了app.manifest
输入图片说明
按下面代码修改,启用dpiAware

  <!-- 指示该应用程序可感知 DPI 且 Windows 在 DPI 较高时将不会对其进行
       自动缩放。Windows Presentation Foundation (WPF)应用程序自动感知 DPI,无需
       选择加入。选择加入此设置的 Windows 窗体应用程序(面向 .NET Framework 4.6)还应
       在其 app.config 中将 "EnableWindowsFormsHighDpiAutoResizing" 设置设置为 "true"。
       
       将应用程序设为感知长路径。请参阅 https://docs.microsoft.com/windows/win32/fileio/maximum-file-path-limitation -->

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

  
  

3、设置DPIScale为true
实现目标:DPI缩放后字体大小不变
确认编译时DPI缩放为100%
在主窗体上放置UIStyleManager控件
输入图片说明
设置DPIScale为true
输入图片说明
编译程序,在不同的DPI缩放下测试编译好的SunnyUI.Demo.exe

SunnyUI.Net:C# .Net WinForm开源控件库、工具类库、扩展类库、多页面开发框架;Sunny's blog:https://www.cnblogs.com/yhuse