I am working on a Windows Form 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 21px shorter than the height value it was at build.

If I then keep building and running my project, the form will decrease by 21px 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 yet to prove if thats the case.

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

Any help or insight would be greatly appreciated!!

  • Is it reproducable behaviour? Can you create new project, make some actions and get same result? If not - I really doubt some here can help you with this issue. – Andy Korneyev Dec 24 '14 at 8:00
  • Thanks for the reply. Will try see if I can reproduce the bahaviour on a clean project, but since this project is quite complex Im worried it might take some trial and error to find the exact action that originally caused this behaviour. I am more hoping if anybody else here has experienced similar behaviour or is aware of any known quirks that produces things like this. Maybe even better yet, how to possibly avoid the form to resize at all by itself at build. – Simon Dec 24 '14 at 8:05

This is an annoying bug and i have suffered similar behavior myself, however there maybe a couple of work arounds, 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 ie

display propertis->settings tab->advance. in the the advance dialog i changed the "DPI Settings" from Large (120dpi) 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.

  • thank 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! – Simon Dec 24 '14 at 8:09
  • None 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 Feb 23 '17 at 17:06
  • This was asked in 2014, however it probably is still a bug – TheGeneral Feb 28 '17 at 3:21

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;
}
  • Thumbs 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 – Ricardo Garcia Oct 4 '17 at 14:27

Ok, so first in response to Saruman's suggested solutions..

1 - None of the controllers in the application where had docked values. A good few were anchored, but none appeared docked. I docked a couple of the main containers I could find, and it didn't seem to make much difference. Admitedly I didnt dock every single controller, but I then moved onto solution 2..

2 - I wasnt sure where to find the DPI settings. Whether somewhere in Visual Studio, or on my machine. So moved onto proposed solution 3..

3 - On the Form initialize, I added 'this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;'. This then seemed to automatically place it above a 'this.ClientSize = new System.Drawing.Size(11264,730)' method, which piqued my interest. With a little further debugging, it appears that when the application builds and intializes, the 'this.ClientSize' property is already set at a very low, more or less, '230x200'. I am not sure where this value comes from, but I wonder if it has anything to do with the initial resizing before it then tries to set it again to something bigger..

Regardless, I came across another suggestion to possibly double check my form's minimum width and height properties, and noticed they were set to 0x0, i'm assuming by default.

So I set the min values to be the same as my form's size value, and on subsequent builds it appears to be keeping it size now! Or at least, it isnt shrinking any more from what I can tell.

Im not sure if setting the minimum form size is an acceptable solution for this bizarre behaviour, but so far it seems to be keeping the app size consistent on each build we do, which is a relief at the moment.

If any one has further knowledge on the ClientSize property and if I am right to be concerned about it's initial low size, would be great to hear it. :)

Figured it out! If you click on the form in "Design View" > "Properties" > "MinimizeBox" and change "True" to "False".

  • This 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. – stackuser83 Jan 10 '17 at 0:27
  • I also stopped having this issue in VS 2017 – Rody Davis Aug 23 '17 at 13:33

I had same problem. My solution:

My PC's system is Windows 10. The resolution of the monitor was 12515 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:

resolution settings

In Turkish "Scale" is "Ölçekle". There are resolution options on the bottom ("ölçekle ve düzenle").

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.