创建DPI感知的应用程序 [英] Creating a DPI-Aware Application

查看:309
本文介绍了创建DPI感知的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#窗体应用程序。当我改变显示器的DPI,所有的控制移动。
我用code this.AutoScaleMode = AutoScaleMode.Dpi ,但它并不能避免的问题。

I have a form application in C#. When I change the monitor's DPI, all the controls move. I used the code this.AutoScaleMode = AutoScaleMode.Dpi, but it didn't avoid the problem.

有没有人有一个想法?

推荐答案

困难,但并非不可能。最好的选择是搬到当然WPF,但可能是不可行的。

Difficult, but not impossible. Your best option is to move to WPF of course, but that might not be feasible.

我花了很多的时间解决这个问题。这里有一些规则/指南,使其正常工作没有FlowLayoutPanel的或TableLayoutPanel中:

I've spent A LOT of time with this problem. Here are some rules/guidelines to make it work correctly without a FlowLayoutPanel or TableLayoutPanel:


  • 始终编辑/设计默认96 DPI(100%)的应用程序。如果您在120DPI(125%f.ex),它会变得非常糟糕,当你回到96 DPI后来与它的工作设计。

  • 我用AutoScaleMode.Font成功,我还没有试过AutoScaleMode.DPI多。

  • 确保您使用的所有容器的默认字体大小(表格,面板,Tab页,用户控件等)。 8,25像素。 preferrably它不应该在文件了.Designer.cs在所有的所有容器,以便它使用从容器类的默认字体设置。

  • 所有容器的必须使用相同的 AutoScaleMode

  • 确保所有容器有以下线在Designer.cs文件中设置:

  • Always edit/design your apps in default 96 DPI (100%). If you design in 120DPI (125% f.ex) it will get really bad when you go back to 96 DPI to work with it later.
  • I've used AutoScaleMode.Font with success, I haven't tried AutoScaleMode.DPI much.
  • Make sure you use the default font size on all your containers (forms, panels, tabpage, usercontrols etc). 8,25 px. Preferrably it shouldn't be set in the .Designer.cs file at all for all containers so that it uses the default font from the container class.
  • All containers must use the same AutoScaleMode
  • Make sure all containers have the below line set in the Designer.cs file:

this.AutoScaleDimensions =新System.Drawing.SizeF(6F,13F); //为96 DPI设计


  • 如果您需要在标签/文本框等设置不同的字体大小设置他们每个控制,而不是设置在容器类的字体,因为使用的WinForms容器字体设置扩展它的内容,并具有f.ex用面板的比它包含不同的字体大小的形式保证让问题。它可能工作,如果形式和窗体上的所有集装箱使用相同的字体大小,但我还没有尝试过。

  • 使用另外一台机器或一个虚拟的Windows安装(VMware的,虚拟PC,VirtualBox的)具有较高的DPI设置立刻对设计进行测试。刚刚从DEV机器上的/斌/ Debug文件夹运行已编译的.exe文件。

我保证,如果你遵循这些原则,你会没事的,甚至当你放置​​控件与特定的锚和不使用flowpanel。我们有一个应用程序内置这种方式部署在数百台机器不同的DPI设置,我们不再有任何投诉。所有表格/集装箱/格/按钮/文本框等大小正确缩放为是字体。影像工作太,但他们往往在高DPI变得有点像素化。

I guarantee that if you follow these guidelines you will be ok, even when you have placed controls with specific anchors and don't use a flowpanel. We have an app built this way deployed on hundreds of machines with different DPI setups and we no longer have any complaints. All forms/containers/grids/buttons/textfield etc sizes are scaled correctly as is the font. Images work too, but they tend to get a little pixellated at high DPI.

编辑:此链接有很多好消息,特别是如果你选择使用AutoScaleMode.DPI:<一href=\"http://stackoverflow.com/questions/185804/how-to-control-the-font-dpi-in-net-winforms-app\">link相关计算器问题

This link has a lot of good info, especially if you choose to use AutoScaleMode.DPI: link to related stackoverflow question

这篇关于创建DPI感知的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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