自定义控件 添加 “智能标签"
2010-07-06 14:33
190 查看
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 }
相关文章推荐
- 自定义控件 添加 “智能标签"
- 为自定义控件添加"自定义属性"
- 在Flash "命令"菜单下,添加新的选项方法
- 无法打开"添加/删除程序"现象解决方法
- html"meta"标签详解
- vc的IDE里,在工程窗口里点右键 "添加文件.... "没反应
- struts标签格式化时间<s:date name="neowaveBloodPressure.monitorTime" format="yyyy-MM-dd HH:mm:ss" />
- Qt 界面使用自定义控件 "提升为"
- 在JS里面,取struts的<html:form>标签里面的<html:text property="title"/>值
- 利用link标签rel="alternate&…
- 关于标签<meta http-equiv="X-UA-Compatible" content="IE=edge" />
- 关于VC++6.0添加文件就出现“microsoft developer studio已停止工作"的解决办法
- GC绘图:绘制Text时,在"&"后的一个字符下添加下划线
- 在做动态添加删除行的时候,使用jquery遇到的问题:$("#participantList tr").eq(i).remove();
- 如何在linux的gcc中添加c语言的外部链接库(“比如说,math.h"
- <input type="image"标签引发的页面提交!
- QT中添加Q_OBJECT时编译提示obj : error LNK2001: 无法解析的外部符号 "public: virtual struct QMetaObject const错误解决方法
- Windows在"移动" 全球最小智能手机呼之欲出
- ScrollView中添加一个android:fillViewport="true"
- 如何让WordPress自动对外链添加"nofollow"标签