Mixed WPF and winforms project DPI awareness

后端 未结 3 544
清酒与你
清酒与你 2020-12-19 08:42

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

3条回答
  •  情深已故
    2020-12-19 09:33

    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 :

     
           true/PM 
     
    

    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).

提交回复
热议问题