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?
Asked
Active
Viewed 4,037 times
2
-
1What kind of C# application? Is this Windows Forms? – Cody Gray - on strike Feb 07 '11 at 14:39
2 Answers
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
-
Ok if i declare DPI awareness in manifest will it work for windows XP as well? – zeeshan malik Feb 08 '11 at 07:07
-
@zeemalik: There might be an easier solution. I'm not sure if you haven't noticed my comment above, but can you tell us what *kind* of C# application you're developing? Are you using Windows Forms (WinForms) or WPF? – Cody Gray - on strike Feb 08 '11 at 07:34
-
We have a windows form application not WPF. How can i make the all the controls and fonts display correctly keeping in mind it can run on XP and higher versions of windows? – zeeshan malik Feb 08 '11 at 08:32
-
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.