日期:2014-05-17  浏览次数:20836 次

为什么在设计器属性中修改控件属性,但不在InitializeComponent写入代码呢?
自己继承了一个combobox,并写了一个new SelectedIndex的属性,设置Browsable为true,这样就在设计器属性中显示了,随便添加几个items,我设置SelectedIndex为1时,设计器中combobox显示索引为1的项,但是运行时依然是空的,也就是SelectedIndex是-1,我在窗口的InitializeComponent中看了一下没有设置SelectedIndex的语句,不是在设计器属性中修改的东西都会在InitializeComponent中自动写一条语句吗,现在我只能自己在InitializeComponent写以一条设置SelectedIndex的语句才好使。

------解决方案--------------------
http://msdn.microsoft.com/zh-cn/library/system.componentmodel.design.serialization.designerserializerattribute.aspx

把Items做序列化