WinForms 缩放/紧凑框架后字体大小不正确
我对如何让我的 winform 正确缩放感到困惑。当我设计一个表单时,在我的例子中是 WVGA,水平方向,它看起来像下面的上图。然而,在设备上,文本会缩放得更大。在设计器中设置较小的字体大小可以帮助我正确完成它,但这不是完成此操作的正确方法。
设计器与设备 http://files.zzattack.org/images/cfwinformscaling_small.png 。
让字体在设计器和我的设备上显示相同的正确方法是什么? AutoScaleMode.Font 属性在 Compact Framework 上不可用,禁用自动缩放也没有帮助(与 AutoScaleMode.Dpi 的结果相同),并且在 Visual Studio 中设置设备的 DPI 似乎也没有帮助。
编辑:我想我现在有点明白了。该表单最初是为 800x480 屏幕、dpi 96x96 设计的。现在,我尝试在 800x480、dpi 192x192 的屏幕上使用它。如果我将 AutoScaleMode 设置为 None,则除了字体之外,表单看起来都不错,因为由于分辨率匹配,不需要移动任何控件或调整大小。但 DPI 不同,这就是字体看起来很糟糕的原因。 96x96 dpi 上的 12pt 字体在 192x192 dpi 屏幕上看起来要大得多。我不明白这一点;我认为情况恰恰相反。
看来“解决方案”是仅缩放字体大小。现在我不相信winforms设计器为此提供了一个很好的、优雅的解决方案,所以我可以递归遍历表单中的所有控件并将它们的字体大小设置为原来的一半。这可行,但它涉及双倍的字体数量创作。
另外,奇怪的字体大小会向下舍入(在较高的 DPI 上!),因此,如果 96x96 表单具有可读性良好的 7pt 字体,则选择 3pt 字体(即使在字体构造函数中传递了 3.5),这会很多可读性较差。这不是一个很好的解决方案。有人知道更好的吗?
I'm confused as to how I can get my winforms to scale properly. When I design a form, in my case WVGA, horizontal orientation, it looks like the upper image below. On the device however, the text is scaled to be a lot larger. Setting a lower fontsize in the designer helps me getting it right, but this can't the the correct way of getting this done.
Designer vs device http://files.zzattack.org/images/cfwinformscaling_small.png.
What is the correct way of getting the fonts to appear equal in both designer and on my device? The AutoScaleMode.Font property isn't available on the Compact Framework, disabling autoscaling doesn't help either (same result as AutoScaleMode.Dpi), and setting the device's DPI in Visual Studio doesn't seem to help either.
Edit: I think I do sort of understand now. The form was originally designed for a 800x480 screen with dpi 96x96. Now, I'm trying to use this on a 800x480 screen with dpi 192x192. If I set AutoScaleMode to None, the form looks alright except for the fonts because none of the controls need to be moved or resized because the resolution matches. The DPI is different though, and that's why the fonts look bad. A 12pt font on 96x96 dpi looks a lot bigger on a 192x192 dpi screen. I don't understand this; I'd think it'd be the opposite way around.
It seems the "solution" would be to scale only the font sizes. Now I don't believe the winforms designer offers a nice, elegant solution to this, so I can just recurse through all controls in my form and set their fontsizes to halve the original.. This works, but it involves double the amount of fonts creations.
Also, odd font sizes get rounded down (on higher DPI!), so if the 96x96 form has a 7pt font which is quite readable, a 3pt font is selected (even if 3.5 is passed in the font constructor), which is a lot less readable. Not quite a nice solution. Does anyone know of a better one?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论