In this post, CodeNaked discusses how to change the TextFormattingModeProperty of the application. This solves my problem (see below) perfectly in .Net 4. However my production application is in .Net 3.5 which doesn't have that property at all. How do I accomplish the same thing in .Net 3.5?
My root problem:
I have a winforms application based in .Net 3.5 that has some WPF controls on certain screens. When the Windows DPI setting is set to 150% (not 120%), scaling occurs as expected. However, as soon as a WPF control is created, the scaling is set back to 100% for all windows. I would like the scaling to remain unchanged.
I created a test application to demonstrate. By default it opens a winform that has a button that will open another winform with a wpf control. Left unchanged, opening the second form will cause scaling to revert to 100%. However, if line 11 in Form1.vb is uncommented, scaling will continue to occur correctly when the second form is opened.
Dim newApp As New App() 'Uncomment to fix automatic scaling
Class App:
Imports System.Windows
Imports System.Windows.Media
Partial Public Class App
Inherits Application
Public Sub App()
TextOptions.TextFormattingModeProperty.OverrideMetadata(GetType(Window), New FrameworkPropertyMetadata(TextFormattingMode.Display, FrameworkPropertyMetadataOptions.AffectsMeasure Or FrameworkPropertyMetadataOptions.AffectsRender Or FrameworkPropertyMetadataOptions.Inherits))
End Sub
End Class
You have to directly define your app is DPI aware
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633543(v=vs.85).aspx
I've created app.manifest file in your project and added
<asmv3:application>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true</dpiAware>
</asmv3:windowsSettings>
</asmv3:application>
where asmv3 is
xmlns:asmv3="urn:schemas-microsoft-com:asm.v3"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With