4

I have a form that inherits from another from. In the designer, whenever I adjust something like control size or location, VS auto-generates a resx file for that form. The resx just contains some KeyValuePairs for comboboxes, w/c are unnecessary really since these values are already defined in the parent class.

Aside from this, the designer.cs also gets update w/ inherited properties such as Text, NumericUpDown.Value, DisplayMember, ValueMember, etc, w/c again are already defined in the parent class.

I know the designer.cs is supposed to be update w/ the new location and size, but I don't want it to update other stuff that's inherited from parent class.

Is there a way to prevent this, and just let the designer update the location and size?

UPDATE: I found that the ComboBox.Items.AddRange() gets added to the Designer.cs and .resx file due to binding logic that I have in OnLoad(). This is primarily preventing the designer to load properly when the form is reloaded on the Designer.

I modified OnLoad to run the binding logic only when DesignMode is false.

The form no longer throws errors when reloading the designer, but some of the control properties are still unnecessarily added back to the Designer.cs whenever I change any property via the property dialog.

UPDATE2: Totally prevented the designer from generating unnecessary control properties by applying suggestion here.

Now all that's generated are control location and size.

Community
  • 1
  • 1
sjlewis
  • 780
  • 2
  • 13
  • 25
  • Is inheriting Form code the right thing to do? If there exists a common piece of UI layout/functionality, shouldn't that code be put into a UserControl? Then that UserControl is added to both forms? – Ritch Melton Mar 03 '11 at 05:57
  • i'm not sure; we already have the common UI/functionality baked into the parent class, but we also allow inheritors to adjust the layout a bit (e.g. position, size) and also allow them to add new controls in the derived form. – sjlewis Mar 03 '11 at 07:27
  • possible duplicate of [How do I keep Visual Studio's Windows Forms Designer from deleting controls?](http://stackoverflow.com/questions/2677646/how-do-i-keep-visual-studios-windows-forms-designer-from-deleting-controls) – sjlewis Apr 23 '15 at 09:29

0 Answers0