Mixed WPF and winforms project DPI awareness

后端 未结 3 537
清酒与你
清酒与你 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:19

    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:

    1. a) (My projects target .NET Framework 4.7.2)
    2. b) (all my forms are set to AutoScaleMode = Font)
    3. In your WinForms Project, add a Reference to WindowsBase (should be the third last entry in the list of Assemblies)
    4. Add "[assembly: System.Windows.Media.DisableDpiAwareness]" to your AssemblyInfo.cs
    5. Add "
    
      
        true/PM
      
    
    

    " into the parental "" 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

提交回复
热议问题