当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
JS dynamically creates a href circular download file. Only 10 or a fixed number of files can be downloaded
Solve the mining virus sshd2 (redis does not set a password and clear the crontab scheduled task)
MySQL optimization
[project training 10] drawing of arrows
System permission program cannot access SD card
Mongodb record
MySQL的意向共享锁、意向排它锁和死锁
[STL] summary of deque usage of sequential containers
301. 删除无效的括号
MySQL重做日志 redo log
English grammar_ Adverb - ever / once
RFID数据安全性实验:C#可视化实现奇偶校验、CRC冗余校验、海明码校验
mysql 索引
如何在 PHP 中进行日期格式验证检查(正则)
Chrome remove duplicate bookmarks
.h5文件忘记数据库名字,使用h5py打印
Linux安装mysql8.0.25
/bin/sh no such file or directory问题
What you need to know about five insurances and one fund
MySQL Redo log Redo log


![[project training] change of linear arrow](/img/a4/7554522c13684d7590d247f28a6965.png)





![[daily training] 513 Find the value in the lower left corner of the tree](/img/97/ab2179d6dbd0536e8cc139659aecc2.png)
