当前位置:网站首页>C DPI adaptation problem
C DPI adaptation problem
2022-06-23 07:03:00 【Wool leek】
C# DPI Adaptation problem ( Some computers )
What is? DPI?
The full name is dots per inch (DPI), Points per inch , On the monitor, it is the number of pixels per inch ,Window In general, the default is 96 dpi As 100% Zoom ratio of , However, it should be noted that this value may not be the real physical value of the display , It's just Windows One of our reference standards .
When we don't want our interface to follow DPI When you change , It can make windows Ignore our program , The code is as follows :
// Before running the whole program, open the first winform In the initialization of , Just execute this method
public static int ignoreDPI()
{
SetProcessDPIAware(); // important
IntPtr screenDC = GetDC(IntPtr.Zero);
int dpi_x = GetDeviceCaps(screenDC, /*DeviceCap.*/LOGPIXELSX);
int dpi_y = GetDeviceCaps(screenDC, /*DeviceCap.*/LOGPIXELSY);
ReleaseDC(IntPtr.Zero, screenDC);
return dpi_x;
}
[DllImport("user32.dll")]
public static extern IntPtr GetDC(IntPtr ptr);
[DllImport("user32.dll", EntryPoint = "ReleaseDC")]
public static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDc);
[DllImport("gdi32.dll")]
public static extern int GetDeviceCaps(
IntPtr hdc, // handle to DC
int nIndex // index of capability
);
[DllImport("user32.dll")]
internal static extern bool SetProcessDPIAware();
const int LOGPIXELSX = 88;
const int LOGPIXELSY = 90;
This is the time , The text in some controls is not displayed correctly , It's because of the font size setting
Now let's think about why DPI Set it high , The font we see will get bigger ? Because the system font is in a fixed size ( Song style 10 No , Physical dimensions are (10/72) Inch ) The design of the , When we DPI Set it high , It means that the font should occupy more pixels , On the premise that the screen resolution remains unchanged , It looks big . So if we set it high DPI, Usually it also means that our monitor is of high resolution , The font inside looks too small , We need to improve DPI To enlarge the content .
If we use system Fonts ( Such as GetStockObject(DEFAULT_GUI_FONT)), In this case, we don't have to worry about , Because the system will set the font at high DPI The corresponding amplification is carried out ; If we were to use CreateFont Self created fonts , Then we have to enlarge the font by ourselves .
summary : If you don't want to be in trouble , You can use it directly windows System font , Such as ( Microsoft YaHei , 12pt / Microsoft YaHei , 10.5pt etc. )
Demo download https://download.csdn.net/download/qq_24905875/10681521
边栏推荐
- Cloud box is deeply convinced to create a smart dual-mode teaching resource sharing platform for Nanjing No. 1 middle school
- Centos7 MySQL records
- mysql 基础查询
- [project training 10] drawing of arrows
- Badly placed ()‘s 问题
- QT designer cannot modify the window size, and cannot change the size by dragging the window with the mouse
- XXL-SSO 实现SSO单点登录
- core. What is JS ---kalrry
- [QT] basic learning notes
- 【STL】pair用法总结
猜你喜欢

cmder
![[STL] summary of pair usage](/img/ba/72697f0f8bf018f1b5884e9cc2be4e.png)
[STL] summary of pair usage

RFID数据安全性实验:C#可视化实现奇偶校验、CRC冗余校验、海明码校验

Chrome remove duplicate bookmarks

xml dtd 记录

The illustration shows three handshakes and four waves. Xiaobai can understand them

直播回顾 | 传统应用进行容器化改造,如何既快又稳?
![[daily training] 513 Find the value in the lower left corner of the tree](/img/97/ab2179d6dbd0536e8cc139659aecc2.png)
[daily training] 513 Find the value in the lower left corner of the tree

Eureka

Business logic design of physical warehouse and virtual warehouse in middle inventory
随机推荐
Using fuser to view file usage
318. 最大单词长度乘积
Common setup modes (Abstract Factory & responsibility chain mode & observer mode)
system 权限程序不能访问sd卡问题
Anti chicken soup speech
MySQL的意向共享锁、意向排它锁和死锁
图解三次握手四次挥手,小白都能看懂
【项目实训】线形箭头的变化
解决挖矿病毒 sshd2(redis未设密码、清除crontab定时任务)
313. 超级丑数
300. 最长递增子序列
Badly placed()'s problem
MySQL重做日志 redo log
QT设计师无法修改窗口大小,无法通过鼠标拖动窗口改变大小的解决方案
English grammar_ Adjective comparative - Level 3 change
[project training] change of linear arrow
js 动态创建a href 循环下载文件只能下载10个或者固定数目的问题
开源OAuth2框架 实现SSO单点登录
idea安装 CloudToolkit 插件
Why can't the index of JS array use negative numbers