ControlDesigner:
public class MyUserControlDesigner : ControlDesigner{ private DesignerActionListCollection _actionLists; public overrIDe System.ComponentModel.Design.DesignerActionListCollection ActionLists { get { if (_actionLists == null) { _actionLists = new DesignerActionListCollection(); _actionLists.Add(new MyUserControlActionList(this)); } return _actionLists; } }}
DesignerActionList:
public class MyUserControlActionList : DesignerActionList{ public MyUserControlActionList(MyUserControlDesigner designer) : base(designer.Component) { } public overrIDe DesignerActionItemCollection GetSortedActionItems() { DesignerActionItemCollection items = new DesignerActionItemCollection(); items.Add(new DesignerActionPropertyItem("DockInParent","Dock in parent")); return items; } public bool DockInParent { get { return ((MyUserControl)base.Component).Dock == DockStyle.Fill; } set { TypeDescriptor.GetPropertIEs(base.Component)["Dock"].SetValue(base.Component,value ? DockStyle.Fill : DockStyle.None); } } }
最后,您需要将设计师附加到您的控件:
[Designer("namespacename.MyUserControlDesigner,AssemblyContainingTheDesigner")]public partial class MyUserControl : UserControl{ // all the code for your control
简要说明
该控件具有与之关联的Designer属性,指出了我们的自定义设计器.该设计器中唯一的自定义是公开的DesignerActionList.它会创建自定义 *** 作列表的实例,并将其添加到公开的 *** 作列表集合中.
自定义 *** 作列表包含bool属性(DockInParent),并为该属性创建 *** 作项.如果正在编辑的组件的Dock属性是DockStyle.Fill,则属性本身将返回true,否则为false,如果DockInParent设置为true,则组件的Dock属性设置为DockStyle.Fill,否则为DockStyle.None.
这将在设计器中显示靠近控件右上角的小“动作箭头”,然后单击箭头将d出任务菜单.
总结以上是内存溢出为你收集整理的c# – 用户控制停靠属性全部内容,希望文章能够帮你解决c# – 用户控制停靠属性所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)