2

I want to make my C# application DPI aware. There is a command available in Windows API called SetProcessDPIAware() but the problem is it only works in Windows Vista and higher versions of Windows and not in XP. How can I make the controls, Buttons and Fonts DPI aware such that it displays correctly regardless what ever Windows version is used?

Wollmich
  • 1,616
  • 1
  • 18
  • 46
zeeshan malik
  • 41
  • 1
  • 6

2 Answers2

6

Calling SetProcessDPIAware doesn't just magically make everything DPI aware for you; its purpose is to declare to Windows that your app has been correctly written to be DPI aware. Furthermore, its use is not recommended; you're supposed to declare DPI awareness in your manifest instead. There's an entire article about this on MSDN.

Aaron Klotz
  • 11,287
  • 1
  • 28
  • 22
2

See my moderately detailed answer on how to make an application respond to DPI settings on this StackOverflow question.

The short version is that you can change all your form's AutoScaleMode to ScaleMode.Dpi.

But it's better to leave it at ScaleMode.Font; fonts get bigger as the DPI increases.

Community
  • 1
  • 1
Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219