How to stop Visual Studio from increasing controls every time I open a Windows form?

I have one Windows form file that every time I open it in Visual Studio, it increases the size of the controls in the designer file. If I save the form, close it in the editor and open it again, then the controls will be a little larger than before. I can see that the size properties in the controls are increasing in the constructor file.

Can someone explain to me how to fix this behavior?

+4
source share
3 answers

To clarify my comment, when a developer loads / saves your form, he will call getters / setters the public properties of the forms and form elements.

This means that if you override the form property, and accessing / setting the specified property has the side effect of resizing the control, this size setting will be reflected in the designer. Then, when you save the form, this new size is saved in the code created by the developer. Each time you re-open the form, this setting will take place.

This also applies to event handlers for properties that are set in the code generated by the constructor.

+2
source

I had problems with visual studio when working on Windows 8 with an HD res vs laptop with the usual 1280 x 800 one

By default, Windows on a new installation for an HD laptop was to increase the font size in Windows programs by 25%

Look under Screen Resolution β†’ Make text or other objects larger or smaller β†’ Select β€œLet me choose one zoom level for all my displays” to see the setting. 125% in my case.

The visual studio seems to set the form or control the AutoScaleMode setting based on the setting described above.

In the form designer: On a low-resolution laptop this.AutoScaleDimensions = new System.Drawing.SizeF (6F, 13F);

Hi, res this.AutoScaleDimensions = new System.Drawing.SizeF (7F, 16F);

+3
source

Just lock your controls so that you cannot accidentally move or resize them.

Just open the form designer, right-click and select "Lock controls" in the context menu.

enter image description here

As for why Visual Studio automatically resizes, I can only speculate.

0
source

All Articles