Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Designer is always trying to change my control

I have a somewhat complex UserControl, and Visual Studio 2008 is giving me a rather harmless annoyance when working with it. Every single time I open the control with the Designer, it decides to immediately change some of the harmless values set by the designer - namely the initialization of Size properties. If I save those changes, close, and reopen, it almost invariably ends up deciding another component of my control needs its initial size changed, ad infinitum. Luckily these changes are harmless since I'm using automatic sizing everywhere, but this is quite annoying to work with. I haven't the foggiest on where to start figuring out what's going wrong, my only thought right now is that the Designer is assigning the results of auto-sizing back into the initial size fields every time I open the control. Any ideas on causes/fixes?

Edit: Also, I am using Application Settings to save sizes of certain resizable child components across runs of the application, but I really hope the Designer is smart enough to understand that it should only ever be using the defaults.

like image 897
Not Sure Avatar asked Apr 27 '09 23:04

Not Sure


People also ask

What is user control in Visual Studio?

A user control is just like the Visual Basic supplied controls, such as TextBox or Button, but you can make your own control do whatever you like with your own code. Think of them like "bundles" of standard controls with custom methods and properties.

What is designer in Visual Studio?

Windows Forms Designer in Visual Studio provides a rapid development solution for creating Windows Forms-based applications. Windows Forms Designer lets you easily add controls to a form, arrange them, and write code for their events. For more information about Windows Forms, see Windows Forms overview.


2 Answers

Maybe it can help:
I noticed that FormDesigner (no WPF, no Web etc) has a strange behaviour if you insert one custom UserControl.
There is a random change of other controls (GroupBox, EditBox, ComboBox) size (to me happened with width).
The controls choosen to resize seems to be random, but across restarting of vs2010 it is always the same. If deleted and reinserted, the designer chooses a different control do randomly resize...

I changed the property AutoScaleMode of my UserControl from "Font" to "Inherit" and it did not happen again.

like image 141
Matteo TeoMan Mangano Avatar answered Oct 18 '22 20:10

Matteo TeoMan Mangano


You're right, the designer often tries to add default values to properties.

Add this on top of the property declaration:

[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]

That will tell the designer to ignore this property.

like image 22
jean Avatar answered Oct 18 '22 20:10

jean