My Windows Form keeps on shrinking/resizing on build
Solution 1
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 Properties → Settings 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.
Solution 2
The Problem
Apparently there is a bug in Visual Studio 2015. It is not calculating the Size
properly when certain circumstances are met. In my case I was using the following...
(Name): Form1
AutoScaleMode: Font
AutoSizeMode: GrowOnly
DoubleBuffered: True
Font: Verdana, 8.25pt
FormBorderStyle: FixedDialog
Icon: (Icon)
MaximizeBox: False
MinimizeBox: False
MinimumSize: 600, 170
Size: 600, 170
StartPosition: CenterParent
Text: MyTitle
Now... If you close this form and open it back up the Size
is still exactly the same (600, 170). If you change the following property...
ControlBox: False
Then you closes the form and open it back up you will notice the Size
has now been changed to (610, 203).
My guess is that the bug is not accounting for two things. One would be the form title bar HEIGHT. The other would be the title bar icon WIDTH. This would be the offset of a WIDTH of 10
pixels and a HEIGHT of 33
pixels.
The Solution
Well you actually have three workarounds. One would be to offset the MinimumSize
. Another would be to actually show the ControlBox
. The last one would be to fix the issue in code by setting the ControlBox
property after the form is initialized.
Offsetting The MinimumSize
:
So the first option would be to offset what you want the MinimumSize
to be by (w:10, h:33). So for example, If you want the MinimumSize
to be (600, 170) then you need to set it to (590, 137). That would actually produce the size you expect to see.
Showing the ControlBox
:
Simply change the following property...
ControlBox: True
Correcting the issue with code:
You will need to change the following property at design-time...
ControlBox: True
Then you will need to set the ControlBox
property to False
after the form is initialized.
public Form1()
{
InitializeComponent();
this.ControlBox = false;
}
Solution 3
This Works for me, on form designer.
Solution 4
- Copy the values of your form size.
- Past it in both Minimum and Maximum Size property.
- Enjoy
Solution 5
I had the same problem. My solution:
My PC's system is Windows 10. The resolution of the monitor was 125%, and I set it to 100%. Then I set the size of the form, not changed.
You can see the resolution settings in this picture:
In Turkish "Scale" is "Ölçekle". There are resolution options on the bottom ("ölçekle ve düzenle").
Simon
Updated on October 21, 2021Comments
-
Simon over 2 years
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?
-
Simon over 9 yearsthank you! Glad to hear it's been experienced before. Will try investigate a couple of your solutions and see if any of them help. Thanks!
-
stackuser83 over 7 yearsThis seemed to fix my VS2012 occurrence of the original poster described problem, but only because I didn't try anything else. Toggling the Minimize back to true did not cause the form to resize again.
-
Arvo Bowen over 7 yearsNone of these
Solutions
worked at all and had any effect on my issue (that is like the question asked). This is related to a bug in VS2015 as described in my answer stackoverflow.com/a/42421969/1039753. -
Arvo Bowen over 7 yearsYou're getting warmer... My answer stackoverflow.com/a/42421969/1039753 might shed some light on the actual issue. Thanks for the question! ;)
-
TheGeneral over 7 yearsThis was asked in 2014, however it probably is still a bug
-
Rody Davis almost 7 yearsI also stopped having this issue in VS 2017
-
Admin almost 7 yearsThumbs Up! Can't believe I simply had to enter the Form Size at "Minimum Size" Property. Been remaking code hundreds of ways for months... Thanks Arvo Bowen
-
rdadkins almost 6 yearsI had this same issue when using VMWare Fusion with a Windows 10 guest. Problem lied with using full retina resolution and having a scaled layout.
-
Stafford Williams over 4 yearsthank-you, I enjoyed this when it stopped my buttons from resizing at runtime.
-
SamWhan over 2 yearsI see now that this basically was what Abdulkadir Avcı suggested, but i didn't grasp that when I read it. :P And none of the other suggestions helped me.
-
ryatkins over 2 yearsThis worked for me.