Visual Studio and DPI issue

别说谁变了你拦得住时间么 提交于 2019-12-01 21:05:55

It has been a while since I worked on this issue, but try setting AutoSize = False. In addition, UseCompatibleTextRendering = True might help.

This is a rather old question, but I want to share my solution/opinion. I ran into a similar problem recently. Actually, I want Visual Studio to keep my WinForms as they are, but them to scale at runtime. I found no consistent summary on how to correctly do that. After some reading and experimenting I came to this solution:

  • Keep the Form’s AutoScaleMode = Font.
  • Set in your Forms Designer: Font = MS Sans; 11px
  • In the Forms Ctor, after InitializeComponent, set: Font = SystemFonts.DefaultFont
  • Enable DPI-Awareness, either through a manifest or by API function SetProcessDPIAwareness

Since AutoScaleMode remains active, all DPI-changing magic works, even per-monitor DPI awareness. What remains, is designing Forms in a way scaling works nicely.

I wrote the details on my Blog: http://www.sgrottel.de/?p=1581&lang=en

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!