views:

17

answers:

0

An annoying behavior of Visual Studio (2008)'s designer is to duplicate any property of a control, which is set inside the control's constructor code to the InitializeComponent() method of the hosting form.

For example, if I create a new user control and write the following line in its Ctor:

this.Text = "Hard Coded Name";

then this same line will appear inside the InitializeComponent() method of any form hosting this control. As long as it's about this kind of properties, it's only annoying because if I were to change the Text property inside the control to: "Better Hard Coded Name", I'd have to go over all hosting controls and manually change the Text value over there too.

The real problem is with ".Add(something)" properties - like if my control is a TableLayoutPanel and I want it to have a certain number of columns and rows. Any col or row style set inside the user control will be duplicated in the hosting form and we end up with having twice as wanted. The count (e.g. ColumnCount) will be as planned but if I were to add cols later on, things will get messy.

Is there a way to signal VS's designer not to duplicate properties? What can I do to avoid this behavior?