C#WinForms禁用DPI缩放 [英] C# WinForms disable DPI scaling

查看:943
本文介绍了C#WinForms禁用DPI缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WinForm应用程序,其中包含许多图像。当我将应用程序放在DPI为120的Win7机器上时,它完全破坏了窗体的外观。有没有办法禁用我的表格的缩放?

I have a WinForm application which hosts many images. When I put the application on a Win7 machines that has a DPI of 120, it completely ruins the look of the form. Is there a way to disable the scaling for my form?

我知道这是不建议的,DPI应该是无缝的,并应由操作系统处理。但是,对于有皮肤的应用程序,图像缩放效果不佳。我不能为所有DPI版本创建图像,所以请不要建议这样做。

I am aware that this is something that is not advised and that DPI should be seamless and handled by the OS. But when it comes to a skinned application, the images do not scale well. I do not have the luxury of creating images for all the DPI variations, so please don't suggest that as an answer.

推荐答案

更改AutoScaleMode属性时,将会遇到更大的问题。增加DPI也会更改系统字体大小。因此,字体大小必须以1/72英寸的磅数表示。字体需要更大,以使DPI增大时具有相同的磅值,并且从相同的距离观看时也要保持文本可读性。

You'll have bigger problems when you change the AutoScaleMode property. Increasing the DPI also changes the system font size. Necessarily so, font sizes are expressed in points, 1/72 inch. The fonts need to be bigger to get the same point size when the DPI increases and keep the text just as readable when viewed from the same distance.

由于控件没有为了不再调整大小,按钮上的文字不再适合。解决此问题的一种方法是按比例更改控件上的字体大小。如果您让所有控件继承表单字体,则很容易,只需更改表单的Font属性即可自动更新控件。明显的缺点是用户将很难阅读文本。当DPI达到每英寸150点甚至更高时,这尤其糟糕,您的UI变成了无法使用的邮票。

Since the controls don't get resized anymore, the text on, say, a button no longer fits. One way to battle this is to change the font size on the controls proportionally. Easy if you let all the controls inherit the form font, just changing the form's Font property automatically updates the controls as well. The clear disadvantage is that the user will have a harder time reading the text. This especially gets bad when the DPI goes to 150 dots per inch and beyond, your UI just turns into an unusable postage stamp.

是的,背景图像需要缩放到适合较大的控件或窗体。现在,图像中的像素不再一对一映射到监视器的像素。默认的Graphics.InterpolationMode值在过滤图像方面做得相当不错。但这取决于图像的种类,结果如何。一张照片几乎总是可以很好地缩放。精细的线条和文字则没有。选择正确的图像对于避免不得不创建单独的图像有很长的路要走。

Yes, background images need to get scaled to fit the larger control or form. A pixel in the image now no longer maps one-to-one to a pixel of the monitor. The default Graphics.InterpolationMode value does a fairly decent job of filtering the image. But it depends on the kind of image how well that turns out. A photo almost always scales very well. Finely detailed line art and text does not. Picking the right kind of image goes a long way to avoiding having to create separate ones.

这个问题在显示器开始具有这种图像之前不会消失。打印机的分辨率。与台式机显示器的600 dpi相比,我们还有很长的路要走。电话将是第一个。

This problem isn't going to go away until monitors start to have the kind of resolution a printer has. We're still a long way from 600 dpi for desktop monitors. Phones will be first.

这篇关于C#WinForms禁用DPI缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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