更改系统 DPI 时如何防止字体调整大小 [英] How to prevent font resize when changing the DPI of the system

查看:61
本文介绍了更改系统 DPI 时如何防止字体调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 C# .NET 3.5 中开发了一个应用程序,我希望它即使在系统 DPI 更改时也能保持相同的窗口大小和字体大小.我在主窗体中将 AutoscaleMode 设置为 None .表单和控件没有调整大小,但所有文本的大小都被放大了.有没有办法可以防止文本放大,或者如何控制它们将它们重置为 96dpi 时的大小?谢谢.

I have developed an application in C# .NET 3.5 and I would like it to maintain the same window size and font size even when the system DPI is changed. I've set AutoscaleMode to None in the main form. The form and controls are not resized but the size of all the texts is upscaled. Is there a way I can prevent texts to upscale or how can I control them to reset them to the size they have at 96dpi? Thanks.

推荐答案

一个潜在的简单解决方案是根据 DPI 的变化按比例更改控件的字体大小.当 DPI 发生变化时,相应地放大/缩小字体大小.

A potentially easy solution is to change the font sizes of your controls proportionally to the changes in DPI. When the DPI changes, scale up/down your font sizes accordingly.

另一种可能的选择是将控件上的所有文本硬渲染"为图像.然后将图像的放大或缩小副本设置为控件的 BackgroundImage 值.如果这样做,请确保适当设置控件的 BackgroundImageLayout 属性.

Another possible option is to "hard-render" all of the text on your controls as images. Then set scaled-up or scaled-down copies of the images as the BackgroundImage values of your controls. If you do this, be sure to set your controls' BackgroundImageLayout properties appropriately.

这篇关于更改系统 DPI 时如何防止字体调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆