Search code examples
.netc#-4.0dpi

Font size not changing when DPI is changed


I have a C# WinForms application, which I have created using VS 2013 on a Windows 7 pro desktop PC, DPI 125. After testing it on a surface pro 4 pc I noticed that something was wrong with the scaling. So, after some soul, stackoverflow, searching :-) I found out that I should add the app.manifest file and set apiAware to true, also change the forms AutoScaleMode to DPI and its AutoSize to true. This has fixed the problem with nearly all of the controls. The problem I have is with a LinkLabel control. The font size on this control does not change with the other controls on the form and it's not inline with them.

What is the best way to fix this issue?

with regards,

es


Solution

  • This is the solution I come up with, resize all the controls based on the content they are using. For example if it is a PictureBox control after the DPI is increased only the control itself is resized not the actual image, so I will resize the control based on the size of the Image.

    so a simple code will look something like this

     Size newSize = missionPbx.Image.Size;
     missionPbx.Size = new Size(newSize.Width + 5, newSize.Height+5);
    

    cheers,

    es