使PropertyGrid控件的属性值可以显示多行的方法
2013-10-28 14:09
127 查看
第一步:重写UITypeEditor的GetEditStyle方法;
第二部:重写UITypeEditor的EditValue方法;
具体实现如下:
调用方式为:
界面代码:
界面实现效果:
第二部:重写UITypeEditor的EditValue方法;
具体实现如下:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms.Design; using System.Drawing.Design; using System.Windows.Forms; namespace PropertyGridDemo { 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; } } }
调用方式为:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace PropertyGridDemo { public class Person { public int Id { get; set; } public string Name { get; set; } public string Sex { get; set; } [EditorAttribute(typeof(PropertyGridRichText), typeof(System.Drawing.Design.UITypeEditor)),Description("The person content!")] public string Content { get; set; } } }
界面代码:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace PropertyGridDemo { public partial class Form1 : Form { public Form1() { InitializeComponent(); propertyGrid1.SelectedObject = new Person(); } } }
界面实现效果:
![](http://images.cnitblog.com/blog/157250/201310/28140819-db851e7b941242fb939b41716ac43517.png)
相关文章推荐
- C# 如何定义让PropertyGrid控件显示[...]按钮,并且点击后以下拉框形式显示自定义控件编辑属性值
- C# 如何定义让PropertyGrid控件显示[...]按钮,并且点击后以下拉框形式显示自定义控件编辑属性值
- C#中PropertyGrid控件绑定对象后更改属性值写回到xml中的一个有效方法
- javascript模板技术 界面显示可以用另外的方法来写了
- js获取服务器控件属性值方法
- C#中datagridview使用tooltip控件显示单元格内容与datagridview自带的tooltip显示单元格内容的方法
- jquery easyui datebox 时间控件默认显示当前日期的实现方法
- c#动态设置combobox控件下拉项宽度以实现下拉项文字可以完全显示。
- Android 控件显示在最上层的方法
- 在Silverlight页面里显示HTML的免费控件下载(附使用方法代码)
- javascript控制页面控件隐藏显示的两种方法
- ASP输出成n列的表格形式显示的方法,多行多列
- 宽带已经连接上了,可以登陆qq,但是浏览器却显示网络连接失败解决方法
- 改变 propertygrid 控件的编辑风格(2)——编辑多行文本
- Ext中显示多行tbar方法
- extJs displayfield控件显示超链接的方法
- Dev 控件不能显示在工具条的解决方法
- CButton控件:mfc自绘按钮类,1张图片显示多种状态的方法
- javascript控制页面控件隐藏显示的方法
- IE中图片不显示火狐中可以显示解决方法