本分步指南介绍在将 UserControl 放在
Windows
窗体上之后,如何将 UserControl 对象用作设计时控件容器。可能会有这样的情况:您想将一个控件拖到 UserControl 中。为做到这一点, UserControl 必须用作控件容器。
默认情况下,UserControl 对象只有在您创建它时才可以用作控件容器。在将 UserControl 放在
Windows
窗体上之后,为让UserControl 承载构成控件,您必须更改 UserControl 的默认设计器。如要为一个组件实现设计时服务,请使用System.ComponentModel 名称空间的 DesignerAttribute 类。DesignerAttribute 出现在类声明前面。通过传递designerTypeName 和 DesignerAttribute 参数初始化 designerTypeName。
designerTypeName 是提供设计时服务的设计器类型的完全合格的名称。传递 designerTypeName 参数的System.Windows.Forms.Design.ParentControlDesigner 和 System.Design 的组合。ParentControlDesigner 类扩展了UserControl 的设计时行为。
designerBaseType 是设计器的基类的名称。用于设计时服务的类必须实现
IDesigner 接口。
using System.ComponentModel.Design;
[Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(IDesigner))] public class UserControl1 :System.Windows.Forms.UserControl { ... }
原文:http://www.cnblogs.com/qingtianhua/p/3521058.html