Fix Form size and dimensions

Posted on 2007-07-19
Last Modified: 2016-08-29
I've been working on a VB .NET 2003 project in Skokie, IL that is used in a factory in Iowa.  
In Iowa the application is displayed on a flat-panel display of 1280 x 1024 pixels.  I tweaked the main form in Iowa to fill that display in Iowa.
This is a screen capture of the form on the display in Iowa:

Before I left Iowa, I tried to fix and lock the screen size and shape and set the screen size as shown in these properties:

When I bring the VB code to Skokie, where I am continuing to work on it, and I don't change the form, and run it on a 21 inch glass monitor set to 1280 x 1024 pixels, the screen looks like this:

Notice the right side of the form is cut off (and the middle is spread out).  Also, in the form design I can't ever SEE the right side of the screen or its controls!

Moreover, after compiling code in Skokie, but not modifying the form, when I go back to Iowa, the screen looks like the Skokie version, losing everything on the right side of the screen!
What caused the screen to reshuffle itself when I come to Skokie?  And remain shuffled when I return ti Ioa? How can I keep the screen fixed like it is in Iowa?

Question by:IntegratedDNA
    LVL 14

    Expert Comment

    I believe this has nothing to do with your program.. but rather how each of the computers video diplay adaptor driver is set up.

    A Maximized screen is a system setting.. that as a programmer we have no control over. It appears, that the desktop settings at the remote site are set for a size larger than the physical size of the monitor. The term for this is a virtual desktop. Display adaptor software provides this type of functionality.

    Next time you are there, right mouse click on the desktop to bring up Display Properties.. and then take a look for the display adaptor's software settings. If no vendor provided settings appear, go to control panel or Start Programs or the System Tray to see if there is Display Adaptor software located there.

    One other thing you may want to check is whether the Display Adaptor's drivers are up to date. If not, you may wwant to update them and then try your program again.

    Author Comment

    Thanks for your comment.  However, within the Visual Basic development environment, the form seems to be truncated when I came to Skokie.  The right side of the form with all its labels is not on the form in the development environment.  I wouldn't think the computer display could affect that.

    Also, when displayed (running) in Skokie, there is more space between the panels on the left, looking like the controls were rearranged (for some reason) by VB.

    Does VB rearrange contyrols on a form on different displays.  Trouble is, it stays rearranged when I go to Iowa.  How can I can I stiop that rearrangement?
    LVL 14

    Expert Comment

    "Does VB rearrange controls on a form on different displays?"..
    With some of the poorly designed Forms that I have seen.. don't I wish.. I'd buy one of those displays in a heartbeat.. <silly grin>.

    Alas, no.. this is not the case.. for if it were VB would not be the number 1 progranmming language in the world. There is something out of whack on the Skokie machine.

    You haven't provided to many specifics.. (video display adaptor, .Net framework SPs applied on both your and the Skokie computer)..  However, there are things you can do:
    1. To isolate the problem, create another VB.Net project and install it on Skokie. If the same thing happens then it is not something specific to your application.
    2. Try creating the project on another development computer and install.
    3. Uninstall and reinstall the .Net framework on Skokie.
    4. (My Favorite).. If you can find another computer with the same video display adaptor and .Net try your appication on it. As I indicated earlier, I still believe this to be a video driver problem.  
    5. Reprogram the GUI in Braille and see if anyone notices.

    Good Luck.. <smile>.
    LVL 38

    Expert Comment

    Before you start brushing up on your Braille, a couple of questions...

    What is the AutoScaleMode on the form?  
    What DPI are set on the video advanced properties in both cases?
    LVL 38

    Accepted Solution

    I think that the problem is that VB.NET does rearrange things based on resolution and DPI.  I experienced a problem with another developer who was working on his laptop.  I would send him things and he'd complain that the forms were all messed up.  We discovered the culprit was this autoscaling based on DPI.  The only resolution we found was to set DPI the same for both computers that were sharing form source, but that was in VS 2003.  For VS 2005, you may be able to get away with changing the AutoScaleMode if you can't change the DPI.  
    LVL 14

    Expert Comment

    Paul.. you jogged my memory.. (what little memory that is left.. heheheh and a <groan>)

    Assisting PaulHews (no points necessary)..

    Scaling Windows Forms.. Last updated Apr 14, 2006.

    If youve spent much time working with Windows applications, youve experienced the display problems that occur when the user changes the display settings from normal fonts to large or extra large fonts. In general, if the user changes the font size, controls on forms do funny things that end up making your application look unpolished: controls end up squeezed together, or the text on a control will be clipped because its too large for the controls bounds. Most developers dont even realize that users can change the appearance of an application.

    A lot of developers just ignore the problem, figuring that users deserve whatever they get if they do something so silly as use anything other than the normal font. Others get around the problem by using specific fonts rather than the default system font. Thats kind of unfriendly, though. Some users have trouble seeing the normal fonts at high display resolutions. Many people, for example, complain that the font on my laptop is too small.

    The .NET Framework supports automatic scaling of Windows Forms so that programmers dont have to worry too much about it. The SDK documentation article, Automatic Scaling in Windows Forms describes the need for automatic scaling, the way that .NET used to work, and the way that .NET 2.0 handles scaling.

    As the article points out, the .NET 2.0 support for scaling completely replaces prior versions. Although the old mechanism is preserved in .NET 2.0 to maintain backward compatibility, the new mechanism is much more robust. The class members that are used to implement the old scaling mechanism are marked as obsolete. According to the article, you can safely delete references to the AutoScale, ApplyAutoScaling, AutoScaleBaseSize, and certain Scale overloads when you upgrade your old .NET code to Framework 2.0.

    Its been my experience that automatic scaling "just works" in .NET 2.0 and that I mostly dont have to fiddle with it. The one place where the automatic scaling needs help is responding to font scheme changes.

    Responding to Font Scheme Changes

    An SDK article, How to: Respond to Font Scheme Changes in a Windows Forms Application, describes the problem. The user can change the system-wide font settings to make the default font appear larger or smaller. Windows Forms dont automatically respond to these changes--you have to code that support yourself. The linked SDK article attempts to show you how, but the article text is confusing and the sample code to which it refers does not exist. Follow these instructions to make your program use the default font and respond to font scheme changes.

    First, create a Windows Forms application. Be sure to add a reference to the Microsoft.Win32 namespace. That namespace contains the definition of the system default font.

    You need to implement a handler for the System.UserPreferenceChanged event that causes the form to scale automatically when the Window category changes. Heres the event handler:

    Sub SystemEvents_UserPreferenceChanged( _
    ByVal Sender As Object, ByVal e As UserPreferenceChangedEventArgs)
      If e.Category = UserPreferenceCategory.Window Then
        Me.Font = SystemFonts.IconTitleFont
      End If
    End Sub

    Because the Forms AutoScaleMode property is by default set to Font, the form will automatically scale whenever you change the forms font. You could verify that if you like by making one of the button click handlers change the font to something different.

    In order for that event handler to be called, you have to hook up the event in the Forms constructor. You also have to set the font to the system default so that your program will get the proper font at startup.

    Public Sub New()
      AddHandler SystemEvents.UserPreferenceChanged, AddressOf SystemEvents_UserPreferenceChanged
      Me.Font = SystemFonts.IconTitleFont
    End Sub

    Finally, you want to make sure that you remove that event handler when the form closes. Otherwise your form will leak memory whenever its opened and closed:

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
      RemoveHandler SystemEvents.UserPreferenceChanged, AddressOf SystemEvents_UserPreferenceChanged
    End Sub

    Note that the above code only works if the Forms AutoScaleMode property is set to Font, or if its set to Inherit and its ultimate parents mode is Font. If AutoScaleMode is set to /something else, then the code will change the font, but the form and its controls will not be scaled accordingly.

    Author Comment

    Last Friday, when I saw the comment of PaulHews about this problems being caused by the DPI's being different, I checked my DPI (In Skokie) and found it to be set at Large, 120 DPI.  I asked someone in Iowa to tell me the DPI there, and they said Normal, 96 DPI.

    I changed my [Skokie] DPI to 96, rebooted the computer.

    To my surprize, the form now looks like it does in Iowa!!!  It was the DPI, after all.  Well done PaulHews!!!

    However, setting the DPI to 96 makes everything on my 21 inch monitor look tiny.

    Author Comment

    I am now back in Iowa, and the form modified in Skokie at 96 DPI looks just right on the Iowa machine.  Well done again, PaulHews.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now