none
Visual Basic 2017; handling Windows Form scaling RRS feed

  • Question

  • I have a project that I have worked on through several generations of Visual Basic.  I have made many changes in my code under Visual Basic 2017.  On my development computers (yes, more than one) I have not had any trouble with the scaling of my application; all of the labels, textboxes, etc all fit well on the screen.  My problem is that my application has been moved to a laptop.  The user of the application needs it on their laptop for business purposes; going out to various sites for our company.  The fonts in labels appear to be larger; hence, either cutting text inside of the fixed label or appears underneath the textbox or other control that is associated to the label.  Text in textboxes also appear to be larger than what the textbox was designed for.  I have checked to see that the user had not increased the Windows Font size to above 100%.  By the way, both my development system and the user's laptop are all running Windows 10 Pro with the latest updates.  I have put Visual Studio 2017 Community Edition on the laptop, copied my solution to it, and ran it under VS2017CE.  It runs as it should and looks fine.  When I copy the executable file to the location the desktop shortcut is pointing to, it appears to run fine as well.  I tested the application at a different resolution and discovered that the issue reappeared.  It must be a scaling issue and I am not sure what I can do about it.  I have viewed articles on the internet that mention using containers and scaling; however, most of these are from 2016 and early 2017.  The people who have posted comments on the articles all say that this appears to be a continuously troublesome area for Windows Forms developers even now.  This troubles me to say the least.

    Thanks for whatever help you can provide.  Maybe we can get the Microsoft Visual Studio team to notice that there is an issue in scaling as well as these developers who utilize high DPI screens (4K screens) and the like.

    Tuesday, October 23, 2018 5:36 PM

All replies

  • Hello,

    Check out the following article starting at "Current support for automatic scaling"

    https://docs.microsoft.com/en-us/dotnet/framework/winforms/automatic-scaling-in-windows-forms


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Tuesday, October 23, 2018 8:01 PM
    Moderator
  • It is a problem with Windows Forms - even if you follow the documentation precisely, there are always remaining problems (and no chance of these being fixed any longer).

    I'll tell you what worked for us:

    1. Set all forms 'AutoScaleMode' to DPI.

    2. Ensure that the 'dpiAware' flag is set to 'true' in the app.manifest.  Otherwise, Windows will take over and give you a horrible blurred magnified display.

    3. Remove all user controls - rely more on shared dialogs instead.  I didn't document fully the nature of the problems, but user controls were definitely not playing by any of the scaling rules very well.

    4. Ensure that all labels have about 30% extra length to handle larger fonts.

    This combination worked for us and solved problems with the common very high resolution issues that surfaced within the last few years.

    WPF would solve these problems, but I can't see moving to yet another legacy UI approach (that's more complex than Windows Forms) unless it gives me a lot more than proper scaling.  I'll wait for the next one thanks.


    Convert between VB, C#, C++, & Java (http://www.tangiblesoftwaresolutions.com)
    Instant C# - VB to C# Converter
    Instant VB - C# to VB Converter


    Tuesday, October 23, 2018 8:37 PM
  • Hello Karen,

    I have viewed the mentioned article.  Sadly, I've never had to deal with Containers as of yet.  Besides that, I have read elsewhere that even that does not help in some cases.  Can you point me in the direction as to where I can find a Container control to utilize in my VB application?  Some of the Microsoft articles on that subject are confusing to say the least.  That article you mentioned is a bit vague for those of us who have never used Containers.  Thanks Karen.

    Wednesday, October 24, 2018 4:09 PM
  • Hello Dave,

    I will look into this and see if this helps me even in the short term until perhaps some other method is discovered.  Karen Payne has posted a link that I looked at before writing my original post.  It may possibly work as well but I have never worked with Containers.

    Wednesday, October 24, 2018 4:13 PM
  • Hello Karen,

    I have viewed the mentioned article.  Sadly, I've never had to deal with Containers as of yet.  Besides that, I have read elsewhere that even that does not help in some cases.  Can you point me in the direction as to where I can find a Container control to utilize in my VB application?  Some of the Microsoft articles on that subject are confusing to say the least.  That article you mentioned is a bit vague for those of us who have never used Containers.  Thanks Karen.

    Although I've never used the following it may be worthwhile trying it out

    https://www.codeproject.com/Tips/1025766/VB-NET-Dynamically-Resize-and-Reposition-All-Contr


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Wednesday, October 24, 2018 6:18 PM
    Moderator