Reputation: 177
I have one windows form file that each time I open it in Visual Studio it increases the size of the controls within the designer file. If I save the form, close it in the editor, and open it again, then the controls are all a little larger than before. I can see that the size properties on the controls are all increasing within the designer file.
Can anyone explain to me how to fix this behavior?
Upvotes: 5
Views: 4362
Reputation: 66
I've had problems with visual studio when running on windows 8 with an HD res laptop vs a regular 1280 x 800 one
The windows default on a fresh install for the HD laptop was to increase font size in windows programs by 25%
Look under Screen Resolution -> Make text or other items larger or smaller -> Select 'Let me choose one scaling level for all my displays' to see the setting. 125% in my case.
Visual studio seems to set the form or controls AutoScaleMode setting based on the setting above.
In the form designer: On low res laptop this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
Hi res this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 16F);
Upvotes: 4
Reputation: 4014
To elaborate on my comment, when the designer loads/saves your form, it is going to call the getters/setters on the public properties of your Form and the Form's controls.
This means that if you've overridden a property of the form, and accessing/setting said property has a side effect of resizing a control, that size adjustment will be reflected in the designer. Then when you save the form, that new size is persisted to the designer-generated code. Each time you reopen the form, this adjustment would occur.
This would also apply to event handlers for properties that are being set within the designer-generated code.
Upvotes: 2
Reputation: 8962
Just lock your controls so that you can't accidentally move or resize them.
Just open the form designer, right click and from the context menu choose "Lock Controls".
As to why Visual Studio is resizing them automatically, I can only guess.
Upvotes: 0