c# property属性和改变编辑多行文本
时间:2010-12-29 来源:秩名
一个常见的属性的使用。其中name 属性没有定义私有字段,而age定义了已有字段。
public sealed class employee { // this property is an automatically implemented property public string name { get; set; } private int32 m_age; public int32 age { get { return(m_age); } set { if (value < 0) // the 'value' keyword always identifies the new value. throw new argumentoutofrangeexception("value", value.tostring(), "the value must be greater than or equal to 0"); m_age = value; } } } 改变
propertygrid 控件的编辑风格(2)——编辑多行文本
效果:
适用场合:
1、 编辑多行文本;
2、 编辑长文本。
步骤一:定义从uitypeeditor 派生的类,示例如下:
using system; using system.windows.forms; using system.drawing.design; using system.windows.forms.design; namespace blog.csdn.net.zhangyuk { /// <summary> /// propertygridmutitext 的摘要说明。 /// </summary> public class propertygridrichtext : uitypeeditor { public override uitypeeditoreditstyle geteditstyle(system.componentmodel.itypedescriptorcontext context) { return uitypeeditoreditstyle.dropdown; } public override object editvalue(system.componentmodel.itypedescriptorcontext context, system.iserviceprovider provider, object value) { try { iwindowsformseditorservice edsvc = (iwindowsformseditorservice)provider.getservice(typeof(iwindowsformseditorservice)); if (edsvc != null) { if (value is string) { richtextbox box = new richtextbox(); box.text = value as string; edsvc.dropdowncontrol(box); return box.text; } } } catch (exception ex) { system.console.writeline("propertygridrichtext error : " + ex.message); return value; } return value; } } }
步骤二:编辑属性类,指定编辑属性。示例如下:
步骤三:设置propertygrid的属性对象。示例如下:
标签分类:
相关阅读 更多 +
- 系统休眠文件删除后果 如何删除计算机的休眠文件 2025-04-22
- 站群服务器是什么意思 站群服务器的作用 站群服务器和普通服务器的区别 2025-04-22
- jQuery插件有何作用 jQuery插件的使用方法 2025-04-22
- jQuery插件有哪些种类 简单的jQuery插件实例 2025-04-22
-