使PropertyGrid控件的属性值可以显示多行的方法
第一步:重写UITypeEditor的GetEditStyle方法;
第二部:重写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();
}
}
}
界面实现效果:

使PropertyGrid控件的属性值可以显示多行的方法的更多相关文章
- python通过win32api轻松获取控件的属性值
		
1.如何利用句柄操作windows窗体 首先,获得窗体的句柄 win32api.FindWindows() 第二,获得窗体中控件的id号,spy++ 第三,根据控件的ID获得控件的句柄(hwnd) ...
 - C#控件事件属性大全
		
C#控件及常用设计整 1.窗体... 1 2.Label 控件... 3 3.TextBox 控件... 4 4.RichTextBox控件... 5 5.NumericUpDown 控件... 7 ...
 - C#常用控件的属性以及方法(转载)
		
-----以前看别人的,保存了下来,但是忘了源处,望见谅. C#常用控件属性及方法介绍 目录 1.窗体(Form) 2.Label (标签)控件 3.TextBox(文本框)控件 4.RichText ...
 - C#常用控件和属性
		
目录1.窗体(Form)2.Label (标签)控件3.TextBox(文本框)控件4.RichTextBox控件5.NumericUpDown控件6.Button(按钮)控件7.GroupBox(分 ...
 - 在C#中使用属性控件添加属性窗口
		
转自原文 在C#中使用属性控件添加属性窗口 第一步,创建在应用程序中将要展现的字段属性为public公有属性.其中,所有的属性必须有get和set的方法(如果不设置get方法,则要显示的属性不会显示在 ...
 - 自定义PropertyGrid控件【转】
		
自定义PropertyGrid控件 这篇随笔其实是从别人博客上载录的.感觉很有价值,整理了一下放在了我自己的博客上,希望原作者不要介意. 可自定义PropertyGrid控件的属性.也可将属性名称显示 ...
 - android软件开发之TextView控件常用属性
		
TextView控件 text属性,设置显示的文本 textColor:设置文本颜色 textSize:设置文本字体大小 autoLink:设置文本为电话,URL连接等的时候是否显示为可点击的链接 c ...
 - C# 如何定义让PropertyGrid控件显示[...]按钮,并且点击后以下拉框形式显示自定义控件编辑属性值
		
关于PropertyGrid控件的详细用法请参考文献: 1.C# PropertyGrid控件应用心得 2.C#自定义PropertyGrid属性 首先定义一个要在下拉框显示的控件: using Sy ...
 - Silverlight中Image控件Stretch属性的四种值比较
		
通过设置Image控件Stretch属性的值可以控制图片的显示形式: 包含的值:None.Fill.Uniform.UniformToFill <Grid x:Name="Layout ...
 
随机推荐
- Java继承概述
			
继承概述 : 父类(超类,基类): 子类(派生类): extends 只能继承一个类,Java不支持多重继承: 子类继承父类之后,子类可以调用父类的属性和方法, 也可以重写父类的属性和方法,还可以增加 ...
 - java 内部类使用 .this 和 .new
			
如果需要生成对外部类对象的引用,可以使用外部类的名字后面紧跟圆点和this,这样产生的引用自动地具有正确的类型,这一点在编译器就被知晓并受到检查,因此并没有运行时开销 //: innerclasses ...
 - 定制自己的new和delete:operator new 和 operator delete
			
new和delete不同用法 基本用法 int * aptr = new int(10); delete aptr, aptr = nullptr; 上面的代码是我们最基本也是最常见的使用new和de ...
 - **如何让CI框架支持service层
			
http://www.bitscn.com/pdb/php/201411/404708.html 大家知道CodeIgniter框架式MVC分层的,通常大家把业务逻辑写到Controller中,而Mo ...
 - Java编程的逻辑 (34) - 随机
			
本系列文章经补充和完善,已修订整理成书<Java编程的逻辑>,由机械工业出版社华章分社出版,于2018年1月上市热销,读者好评如潮!各大网店和书店有售,欢迎购买,京东自营链接:http:/ ...
 - .NetCore 结合微服务项目设计总结下实践心得
			
以下内容全是在项目中的体验,个人理解心得 起源 2017年7月开始接触.NetCore,当时还是因为Idr4的原因,之前的项目都是用的Idr3做,后面接触到Idr4后,决定以后所有项目都使用.NetC ...
 - #JS attr和prop的区别
			
HTML元素固有属性:使用prop方法 HTML元素自定义属性:使用attr方法
 - HTML5 标签语法变化和使用概念
			
1.H5与H4的区别 概念的变化: H5更注重内容与结构,不再只专注于表现. 声明与标签: 新的声明背简化: <!DOCTYPE html> <meta charset=utf-8& ...
 - chrome书签(收藏栏)的导入导出
 - ZOJ Monthly, March 2018 题解
			
[题目链接] A. ZOJ 4004 - Easy Number Game 首先肯定是选择值最小的 $2*m$ 进行操作,这些数在操作的时候每次取一个最大的和最小的相乘是最优的. #include & ...