Visual Studio and DPI issue

后端 未结 2 1866
梦如初夏
梦如初夏 2021-01-21 00:51

I am developing a Windows Forms application using VS2008 on Windows Vista. I tried to run my application on Windows XP the other day, and everything on GUI was messed up. I real

相关标签:
2条回答
  • 2021-01-21 01:05

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

    0 讨论(0)
  • 2021-01-21 01:17

    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

    0 讨论(0)
提交回复
热议问题