Designer属性 c#

来源:互联网 发布:mysql注入点测试 编辑:程序博客网 时间:2024/06/16 18:20

如何将 UserControl 对象用作设计时控件容器。可能会有这样的情况:您想将一个控件拖到 UserControl 中。为做到这一点, UserControl 必须用作控件容器。


默认情况下,UserControl 对象只有在您创建它时才可以用作控件容器。在将 UserControl 放在 Windows 窗体上之后,为让 UserControl 承载构成控件,您必须更改 UserControl 的默认设计器。如要为一个组件实现设计时服务,请使用 System.ComponentModel 名称空间的 DesignerAttribute 类。DesignerAttribute 出现在类声明前面。通过传递 designerTypeNameDesignerAttribute 参数初始化 designerTypeName

designerTypeName 是提供设计时服务的设计器类型的完全合格的名称。传递 designerTypeName 参数的 System.Windows.Forms.Design.ParentControlDesignerSystem.Design 的组合。ParentControlDesigner 类扩展了 UserControl 的设计时行为。

designerBaseType 是设计器的基类的名称。用于设计时服务的类必须实现 IDesigner 接口。


如下所示将 System.ComponentModel.DesignerAttribute 属性应用到该控件:

  1. [Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(IDesigner))] public class UserControl1 :System.Windows.Forms.UserControl {      ...}

 

原创粉丝点击