Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio - new "default" property values for inherited controls

I'm looking for help setting a new default property value for an inherited control in Visual Studio:

class NewCombo : System.Windows.Forms.ComboBox
{
  public NewCombo() { DropDownItems = 50; }
}

The problem is that the base class property DropDownItems has a 'default' attribute set on it that is a different value (not 50). As a result, when I drag the control onto a form, the designer file gets an explicit mycontrol.DropDownItems = 50; line.

At first, this doesn't matter. But if later I change my inherited class to DropDownItems = 45; in the constructor, this does not affect any of the controls on any form since all those designer files still have the value 50 hard-coded in them. And the whole point was to have the value set in one place so I can deal with the customer changing his mind.

Obviously, if I were creating my own custom property in the subclass, I could give it its own designer default attribute of whatever I wanted. But here I'm wanting to change the default values of properties in the base. Is there any way to apply Visual Studio attributes to a base class member? Or is there some other workaround to get the result I want?

like image 868
Clyde Avatar asked Aug 10 '08 22:08

Clyde


1 Answers

In your derived class you need to either override (or shadow using new) the property in question and then re-apply the default value attribute.

like image 160
Andrew Peters Avatar answered Oct 19 '22 10:10

Andrew Peters