Problems with Visual Studio and DPI

I am developing a Windows Forms application using VS2008 on Windows Vista. I tried to run the application on Windows XP the other day, and everything in the GUI was corrupted. I realized that I developed the application using the 120 DPI setting in Windows Vista, and my XP was set to 96 dpi.

There are several UserControls in my application, and all of them are compressed even in Visual Studio itself if I change my DPI to 96. I am sure that many people use Visual Studio in high DPI these days. So, how can I make sure that my GUI is not confused in both Visual Studio and runtime?

EDIT: I read a couple of articles on this issue, and I found out that I have to set AutoScaleMode to None. However, this still does not prevent my shortcuts from adapting the new DPI settings set by the operating system. I need my labels not to grow / contract because other GUI elements have patch sizes.

+3
user-interface dpi visual-studio winforms autoscalemode
source share
2 answers

It has been a while since I worked on this problem, but try setting AutoSize = False. Also, UseCompatibleTextRendering = True can help.

0
source share

This is a pretty old question, but I want to share my solution / opinion. I recently encountered a similar problem. In fact, I want Visual Studio to keep my WinForms as they are, but scale them at runtime. I did not find a consistent resume on how to do this correctly. After some readings and experiments, I came to this solution:

  • Save the forms AutoScaleMode = Font .
  • Install in your form constructor: Font = MS Sans; 11px Font = MS Sans; 11px
  • In Ctor Forms, after InitializeComponent , set: Font = SystemFonts.DefaultFont
  • Enable DPI-Awareness, either through the manifest, or through the SetProcessDPIAwareness API SetProcessDPIAwareness

Since AutoScaleMode remains active, all DPI-changing magic works even when recognizing DPI on the monitor. What remains is developing Forms in such a way that scaling works great.

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

0
source share

All Articles