Designer不会为子控件的属性生成代码.为什么?

Gab*_*iel 6 c# user-controls windows-forms-designer

I created SubCtrl inheriting UserControl. It has no code. I created then Ctrl, which also inherits UserControl. It has a SubCtrl in it and its only code means to expose it publicly so it appears in the property list of Ctrl:

public subctrl.SubCtrl SUBCTRL
{
    get { return this.subCtrl1; }
}
Run Code Online (Sandbox Code Playgroud)

Then I created a simple Form project which only has a Ctrl in it and no code. As I wanted, SUBCTRL appears in the property list of Ctrl so I can change things. I changed the background color (say, to red), and the subctrl turned red in the designer.

But magically, when I run the project, it turns back to the standard gray. It appears that no code is generated in Form1.Designer.cs to change SUBCTRL's back color to red. If I write it by hand, it works, but that's not what I want. It should be automatic, obviously.

The Ctrl, on the other hand, behaves normally. The code is generated and everything works happily.

子控制有什么问题?

SLa*_*aks 10

加入[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]物业.