none
High dpi messing up my WinForm sizes

    Question

  • I have a problem with my new laptop that are running windows 10. It uses 3840x2160 resolution. When i open a existing c# project all sizes in the forms are changed!

    Example: I open the project on my old laptop (windows 8.1 with a much lower dpi screen) and the form size is 635x270. When i pull the project and open it on my new laptop the form size is 1688x646!!! Visual studio have changed the size automaticly! The changes are not saved unless i make a gui change, for example drag a button or something. Then every size and location in the form changes!

    Is there a setting that i can change that fixes this? This must be a win10/VS 2015 bug! Or am i missig something?


    "Life would be much easier if i only had the sourcecode"

    Saturday, November 07, 2015 3:54 PM

Answers

  • Example: I open the project on my old laptop (windows 8.1 with a much lower dpi screen) and the form size is 635x270. When i pull the project and open it on my new laptop the form size is 1688x646!!! Visual studio have changed the size automaticly!


    Hi this is the default behaviour of Visual Studio. When writing WinForms applications for different dpi settings, write it on the machine that has the lowest one (typically 96 dpi in both directions). You can also play around with the AutoScaleMode of the Forms and Controls (but Backup your project before doing!) , watch the AutoScaleBaseSize then... Especially check the AutoScaleMode.Dpi setting

    Regards,

      Thorsten


    Saturday, November 07, 2015 5:27 PM

All replies

  • Maybe some screenshots would help?

    Dialog units are based on font size to allow for a dialog to show up correctly independent of DPI.  Is this a static dialog or are you positioning things on it programmatically?  If the latter, you should read up on Dialog Units to figure out how to properly place the items.

    A


    I don't mind someone marking a post as "Proposed as answer", but DO NOT mark it as "Answered". If I am the OP, I will decide if a post actually answers my post or not. Thank you.

    Saturday, November 07, 2015 4:43 PM
  • Example: I open the project on my old laptop (windows 8.1 with a much lower dpi screen) and the form size is 635x270. When i pull the project and open it on my new laptop the form size is 1688x646!!! Visual studio have changed the size automaticly!


    Hi this is the default behaviour of Visual Studio. When writing WinForms applications for different dpi settings, write it on the machine that has the lowest one (typically 96 dpi in both directions). You can also play around with the AutoScaleMode of the Forms and Controls (but Backup your project before doing!) , watch the AutoScaleBaseSize then... Especially check the AutoScaleMode.Dpi setting

    Regards,

      Thorsten


    Saturday, November 07, 2015 5:27 PM
  • isn't there some kind of workaround? I dont want to rewrite alot of projects and forms just because i upgraded my computer!!

    If i do a single change to the GUI all the sizes of the control changes! I dont want VS to automaticly rewrite my code! It creates alot of problems for us!


    "Life would be much easier if i only had the sourcecode"

    Saturday, November 07, 2015 7:15 PM
  • Wow, that is such a lousy design. Microsoft doesn't disappoint with their tools.

    I don't mind someone marking a post as "Proposed as answer", but DO NOT mark it as "Answered". If I am the OP, I will decide if a post actually answers my post or not. Thank you.

    Saturday, November 07, 2015 10:29 PM
  • Wow, that is such a lousy design. Microsoft doesn't disappoint with their tools.


    Then don't write a WinForms application. WPF applications have been out for almost 10 years, and part of the motivation for this technology is that it is vector-based, and gets around the problem of DPI.
    Sunday, November 08, 2015 12:17 AM
  • Example: I open the project on my old laptop (windows 8.1 with a much lower dpi screen) and the form size is 635x270. When i pull the project and open it on my new laptop the form size is 1688x646!!! Visual studio have changed the size automaticly! The changes are not saved unless i make a gui change, for example drag a button or something. Then every size and location in the form changes!

    Hi,

    what in your opinion Visual Studio should do? If you create a 6 inches wide form on a 96 dpi system and edit it in the designer on a 150 or more dpi system, the designer will show it at a 6 inch wide size and then save - of course - the size in pixels it takes on the high dpi system - which in pixels is a lot more than on the other system...

    What you can do is disable all autoscaling and handle it yourself, but this is may be a lot more complex than just finding the correct (fitting your needs) settings of the autoscalemode and the autoscalebasesize. Also use Anchoring, Docking in a dpi-variable-friendly way and maybe use the FlowLayoutPanel and the TableLayoutPanel.

    Handling different DPI settings is around for at least 10 years. So if you write production code and (write or maintain) WindowsForms-programs, you should have cared for it already. If you write code for yourself and some friends or interrested persons, you always can share the whole solutions, so people can modify the code in cases something goes wrong. (I know, writing code at home can never be as good as production code, since you simply do not have the testing environment to care for all cases...) You also could use WPf which is a great advantage in using different systems/Os-Layouts etc.

    Regards,

      Thorsten

    Sunday, November 08, 2015 9:39 PM
  • Wow, that is such a lousy design. Microsoft doesn't disappoint with their tools.

    Easy to say such a thing. Provide suggestions to improve those tools instead. Criticize in a positive way. Report bugs to Ms-connect if something is not ok, and provide workaroudns etc. Tell in a clear way, what excactly is disappointing you ("ProgramXYZ is too slow, takes too much ram, has may bugs" etc.).

    So my question is: What should Visual Studio do in this case to not disappoint you...

    Regards,

      Thorsten

    Sunday, November 08, 2015 9:50 PM
  • Wow, that is such a lousy design. Microsoft doesn't disappoint with their tools.


    Easy to say such a thing. Provide suggestions to improve those tools instead. Criticize in a positive way. Report bugs to Ms-connect if something is not ok, and provide workaroudns etc. Tell in a clear way, what excactly is disappointing you ("ProgramXYZ is too slow, takes too much ram, has may bugs" etc.).

    Been there, done that.  I've done such things (reported bugs, specified solutions, stated workarounds) in the past and still do.  I don't however, have time to report every bug or else I'd never get any work done and when I have, have been mostly disappointed in MS responses.  I use MS products now only when I have to, and avoid them when I can.  Unfortunately, when they're the only game in town, or there is a lot of legacy one has to deal with, it is not always possible to do much other than vent.

    So my question is: What should Visual Studio do in this case to not disappoint you...

    In this case, I'd say that there should be a proper mathematical scaling done so this crap doesn't happen.  Dialog Units were an attempt to make it so that a dialog would look close to being the same from one monitor/DPI to another.  An attempt I might add, that has had some issues. However, this still shouldn't stop it from being capable to be better translated from one development environment to another.  Yes, there will be rounding issues, but those issues can be mitigated by adding constants to the resource file spec.

    A


    I don't mind someone marking a post as "Proposed as answer", but DO NOT mark it as "Answered". If I am the OP, I will decide if a post actually answers my post or not. Thank you.

    Monday, November 09, 2015 4:08 PM
  • Been there, done that.  I've done such things (reported bugs, specified solutions, stated workarounds) in the past and still do.  I don't however, have time to report every bug or else I'd never get any work done and when I have, have been mostly disappointed in MS responses.  I use MS products now only when I have to, and avoid them when I can.  Unfortunately, when they're the only game in town, or there is a lot of legacy one has to deal with, it is not always possible to do much other than vent.

    Hi,

    ok then. I myself also am complaining sometimes about the quality of "some" ;-) Software... So I myself will have to read my reply again...

    Regards,

      Thorsten

    Tuesday, November 10, 2015 8:36 AM
  • The last MS product I used (MS VS Community 2015) took my computer down for 4 working days when I tried to uninstall it.

    Yeah, I'm a bit jaded.

    A


    I don't mind someone marking a post as "Proposed as answer", but DO NOT mark it as "Answered". If I am the OP, I will decide if a post actually answers my post or not. Thank you.


    • Edited by A D R I A N Tuesday, November 10, 2015 5:09 PM
    Tuesday, November 10, 2015 5:08 PM
  • Hi,

    what in your opinion Visual Studio should do? If you create a 6 inches wide form on a 96 dpi system and edit it in the designer on a 150 or more dpi system, the designer will show it at a 6 inch wide size and then save - of course - the size in pixels it takes on the high dpi system - which in pixels is a lot more than on the other system...

      Thorsten

    I am not sure how i want it to handle. I think that i overreacted abit when i first encountered the issue.

    The problem now is more how i get alot of xyz.designer.cs changes to sizes and locations when i commit  UI changes. These automatic changes can very easily hide the real changes i made to the UI!

    I have tested the program on both a low and high dpi system and mostly looks ok on both no matter what system that made the last change. Have one instance where the GUI was changed quite a bit, but im not sure if that was something i did while testing :/



    "Life would be much easier if i only had the sourcecode"

    Wednesday, November 11, 2015 9:14 AM
  • Hi Anders-Sweden,

    If you have resolved your problem, please mark the helpful reply as answer, which can help other communities who has the same problem.

    If not, please clarify current problem you are facing.

    In my opinion, it is a default behaviour of Visual Studio, which as Thorsten said. I suggest you post your idea to User Voice for this problem.

    https://visualstudio.uservoice.com/forums/121579-visual-studio-2015

    Best Regards,
    Weiwei

    Monday, November 16, 2015 9:57 AM
    Moderator
  • Wow, that is such a lousy design. Microsoft doesn't disappoint with their tools.



    Then don't write a WinForms application. WPF applications have been out for almost 10 years, and part of the motivation for this technology is that it is vector-based, and gets around the problem of DPI.

    It's a little absurd to assume no one has to support legacy applications using WinForms. Yeah in 20/20 hindsight everything should be written in WPF but that doesn't change the fact I currently am employed to maintain a massive winforms code base in which I did not originally develop. Additionally I'm using a surface book and it's a bit ridiculous that MICROSOFT Visual Studio has such lousy support for my MICROSOFT Surface Books DPI and this also extends to SSMS which has terrible support for high dpi. Basically my surface book is unusable for my work and the PC was a waste of money.
    Tuesday, March 22, 2016 11:39 PM
  • Microsoft shared a solution which allows you to run Visual Studio with display scaling enabled and I blogged about it here:
    https://code4ward.net/2016/11/29/visual-studio-winforms-designer-on-highdpi/

    Stefan Koell | http://www.code4ward.net

    Tuesday, November 29, 2016 10:59 AM