C# – My Windows Form keeps on shrinking/resizing on build

cformsvisual-studio-2013windows-forms-designer

I am working on a Windows Forms project. It contains a tab controller with multiple pages and multiple controls on each.

It appears that relatively recently, after some form changes, that each time I build and run the solution the form resizes/shrinks.

So if I set the size of the form height to 768, once I click 'Start' to build and run it, I can actually catch a glimpse of it resizing itself during the process and then the form loads 21 pixels shorter than the height value it was at build for.

If I then keep building and running my project, the form will decrease by 21 pixels each time, making it smaller and smaller with every build.

We think it might have been introduced when we added the 'DataGridView' controller to one of the tabs, but we have yet to prove if that's the case.

Is there a reason why this would be happening, and what could be doing this?
Why would it resize itself during build run time?

Best Answer

This is an annoying bug, and I have suffered similar behavior myself. However, there maybe a couple of workarounds, however be warned though, these may or may not help and sound a little hacky.

Solution 1

If your control isn't docked, docking may help.

Solution 2

You might be able to change your DPI settings to eliminate the problem, i.e.:

Display PropertiesSettings tab → Advanced. In the the Advanced dialog I changed the "DPI Settings" from Large (120 dpi) to Normal (96 dpi).

Solution 3

This is maybe due to AutoScaleMode-property. Your forms may have been designed with a different DPI or font settings than you have now in Windows display settings. Try setting the AutoScaleMode-property to None in your form and offending controls, and they won't be automatically re-sized anymore.