Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Visual Studio-新";“违约”;继承控件的属性值_C#_.net_Vb.net_Visual Studio - Fatal编程技术网

C# Visual Studio-新";“违约”;继承控件的属性值

C# Visual Studio-新";“违约”;继承控件的属性值,c#,.net,vb.net,visual-studio,C#,.net,Vb.net,Visual Studio,我正在寻找帮助,为Visual Studio中继承的控件设置新的默认属性值: class NewCombo : System.Windows.Forms.ComboBox { public NewCombo() { DropDownItems = 50; } } 问题在于基类属性DropDownItems上设置了一个不同值(不是50)的“default”属性。因此,当我将控件拖到窗体上时,设计器文件会得到一个显式的mycontrol.DropDownItems=50行 起初,这并不重要。但

我正在寻找帮助,为Visual Studio中继承的控件设置新的默认属性值:

class NewCombo : System.Windows.Forms.ComboBox
{
  public NewCombo() { DropDownItems = 50; }
}
问题在于基类属性
DropDownItems
上设置了一个不同值(不是50)的“default”属性。因此,当我将控件拖到窗体上时,设计器文件会得到一个显式的
mycontrol.DropDownItems=50

起初,这并不重要。但是如果以后我将继承的类更改为
DropDownItems=45
在构造函数中,这不会影响任何窗体上的任何控件,因为所有这些设计器文件中仍然硬编码了值50。关键是把价值设定在一个地方,这样我就可以处理客户改变主意的问题


显然,如果我在子类中创建自己的自定义属性,我可以给它自己的designer默认属性。但在这里,我想更改基中属性的默认值。有没有办法将Visual Studio属性应用于基类成员?或者是否有其他解决方法来获得我想要的结果?

在派生类中,您需要覆盖(或使用new进行阴影处理)有问题的属性,然后重新应用默认值属性