试试这是否有效
[TypeConverter(typeof(ExpandableObjectConverter))]
public class MyClass
{
// Some staff
}
public class MyControl : UserControl
{
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Content)]
public MyClass MyObj { get; set; }
}
用户评论后编辑:
此测试代码按预期工作:
public partial class MyControl : UserControl
{
public MyControl()
{
InitializeComponent();
MyObj = new MyClass();
}
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Content)]
public MyClass MyObj { get; set; }
}
[TypeConverter(typeof(ExpandableObjectConverter))]
public class MyClass
{
public string Test { get; set; }
}
再次编辑:
如果您希望属性编辑器的行为与您描述的一样,我能给您的最简单的解决方案是
public class MyClass : Control // if it must be visible on form
或者
public class MyClass : Component // if it must be just a component