Hooch
Hooch

Reputation: 29693

How to make WinForms application completely ignore any kind of DPI settings?

I have WinForms application written in VB .NET that "explodes" on non default DPI settings. This applications uses some ActiveX controls that just don't work with scaling.

I'm kindly asking you not to suggest me to rewrite it, move it to WPF and this kind of advices. I am fully aware that this application is bad, really bad. My job is just to make it "work".

Is there any way to make it so that application ignores completely any DPI setting? Any solution is good one as long as it works.

Upvotes: 3

Views: 2601

Answers (3)

rohit21agrawal
rohit21agrawal

Reputation: 1068

Adding this to your manifest file should do the trick:

 <asmv3:windowsSettings 
    xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
       <dpiAware>false</dpiAware>   
 </asmv3:windowsSettings>

Upvotes: 2

adigostin
adigostin

Reputation: 637

Right-click the executable -> Properties -> Compatibility -> Check "Disable display scaling on high DPI settings". (Might be slighly different on Windows version other than 10.) This did it for me for legacy applications that "explode".

Upvotes: 1

CodeIT
CodeIT

Reputation: 91

Try setting AutoScaleMode to None for automatic scaling. You probably also have to 'scale' the font. This can be done by adding the following before InitializeComponent

Font = new Font(Font.Name, Font.Size * 96f / CreateGraphics().DpiX, Font.Style, Font.Unit, Font.GdiCharSet, Font.GdiVerticalFont);

I don't know how the hosted ActiveX control responds to these settings. Please let me know when you tried.

Upvotes: 0

Related Questions