using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Text; using System.Windows.Forms; using System.ComponentModel.Design; using System.Windows.Forms.Design; namespace ClassLibrary1 { [Designer(typeof(CreateControlDesigner))] public partial class UserControl1 : UserControl { public UserControl1() { InitializeComponent(); } /// <summary> /// set label text /// </summary> public string lb { get { return this.label1.Text; } set { this.label1.Text = value; } } private bool isselectchk; /// <summary> /// checked box /// </summary> public bool IsSelectchk { get { return isselectchk; } set { isselectchk = value; this.checkBox1.Checked = isselectchk; } } public string Lb2 { get { return this.label2.Text; } set { this.label2.Text = value; } } private int se = 0; public int CcbSelectedIndex { get { return se; } set { se = value; this.comboBox1.SelectedIndex = se; } } } // End class #region Create Designer class CreateControlDesigner : System.Windows.Forms.Design.ControlDesigner { private DesignerActionListCollection actionlist = null; public override DesignerActionListCollection ActionLists { get { if (actionlist == null) { actionlist = new DesignerActionListCollection(); actionlist.Add(new CustomControlActionList(this.Component)); } return actionlist; } } } // End class #endregion #region Action List [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")] class CustomControlActionList : System.ComponentModel.Design.DesignerActionList { private UserControl1 usercontrol; private DesignerActionUIService actionui; public CustomControlActionList(IComponent component) : base(component) { this.usercontrol = component as UserControl1; this.actionui = GetService(typeof(DesignerActionUIService)) as DesignerActionUIService; } private PropertyDescriptor GetPropertyByName(string propertyname) { PropertyDescriptor pro; pro = TypeDescriptor.GetProperties(usercontrol)[propertyname]; if (pro != null) return pro; else throw new ArgumentException("找不到此属性名称!", propertyname); } public string Lb { get { return usercontrol.lb; } set { GetPropertyByName("lb").SetValue(usercontrol, value); } } public bool IsSelect { get { return usercontrol.IsSelectchk; } set { GetPropertyByName("IsSelectchk").SetValue(usercontrol, value); } } public string lb2 { get { return usercontrol.Lb2; } set { GetPropertyByName("Lb2").SetValue(usercontrol, value); } } public int ccbselectedindex { get { return usercontrol.CcbSelectedIndex; } set { GetPropertyByName("CcbSelectedIndex").SetValue(usercontrol, value); } } public override DesignerActionItemCollection GetSortedActionItems() { DesignerActionItemCollection items = new DesignerActionItemCollection(); items.Add(new DesignerActionHeaderItem("显示在标题上的文本")); items.Add(new DesignerActionPropertyItem("Lb", "Label Text", "值", "输入名称")); items.Add(new DesignerActionPropertyItem("IsSelect", "Select", "Custom Category", "是否选择")); items.Add(new DesignerActionPropertyItem("lb2", "显示名称", "值", "输入名称")); items.Add(new DesignerActionPropertyItem("ccbselectedindex", "状态", "这是什么", "请选择式样")); // items.Add(new DesignerActionTextItem("Custom Smart Tag", "Custom Category")); //items.Add(new DesignerActionMethodItem(this, "ChangeText", "Change Text", "Custom Category", "呼叫方法", true)); return items; } } //End class #endregion }