I have a C# program that uses both winforms and WPF and I\'m struggling to get it to work in high DPI environments. Currently, if I remove all WPF projects from the solution
Thank you so much for your answer @rohit21agrawal!
I had a quite similar complex Win Forms solution that whenever I opened a docked Form within WeifenLuo's DockPanelSuite, the Form resized and messed-up the whole GUI.
Now, after a couple of years trying different approaches (and none of them working) you saved my life!
In Addition to your answer for every other developer out there wondering how to accomplish your solution:
[assembly: System.Windows.Media.DisableDpiAwareness]
" to your AssemblyInfo.cs<application xmlns="urn:schemas-microsoft-com:asm.v3"> <windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings"> <dpiAware>true/PM</dpiAware> </windowsSettings> </application>
" into the parental "<assembly>…</assembly>
" section of your app.manifest file
In my case, that worked like a charm :-) Eventually I am able to move the Form between different Displays (one 4K with 175% and another Full HD with 125% Font Scale) and it immediately redraws/re-renders all controls!
Again, thank you very much! Cordt
When WPF is loaded into a project, it promotes the process to be System DPI Aware. In order to get around this, first : 1) set [assembly: DisableDpiAwareness] attribute above the namespace declaration in your entry assembly 2) you can add an app.manifest file in your project and add the following :
<asmv3:windowsSettings
xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true/PM</dpiAware>
</asmv3:windowsSettings>
This should render your WinForms and WPF content both at the right target DPI. (This will however fail to scale if you have a multi monitor setup with different DPIs).
My colleague finally worked this one out. As none of the config settings etc would work for this project, we attempted to remove the winforms shell and replace it with a WPF shell. Once the main shell project was re-written in WPF, all the 'plugins' appeared in the correct DPI scaling.
Not the best fix I know considering it involves a re-write of existing code, however this was the only thing that sorted the problem for us.