使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 ...
随机推荐
- Coursera台大机器学习技法课程笔记08-Adaptive Boosting
将分类器组合的过程中,将重点逐渐聚焦于那些被错分的样本点,这种做法背后的数学原因,就是这讲的内容. 在用bootstraping生成g的过程中,由于抽样对不同的g就生成了不同的u,接下来就是不断的调整 ...
- MySQL 数据库性能优化之SQL优化【转】
优化目标 减少 IO 次数IO永远是数据库最容易瓶颈的地方,这是由数据库的职责所决定的,大部分数据库操作中超过90%的时间都是 IO 操作所占用的,减少 IO 次数是 SQL 优化中需要第一优先考虑, ...
- 移动端经常出现的兼容问题,谈谈移动端应用或者wap站的一些优化技巧和心得
移动端经常出现的兼容问题,谈谈移动端应用或者wap站的一些优化技巧和心得 1. 安卓浏览器看背景图片,有些设备会模糊. 因为手机分辨率太小,如果按照分辨率来显示网页,字会非常小,安卓手机 ...
- 《Photoshop智能手机APP界面设计》学习笔记-转
第一章 APP用户界面基础 1.1 手机UI设计相关基本概念 1.1.1 什么是UI设计 UI(User's Interface)即用户界面,它不仅仅是美化界面,还需要研究用户,让界面变得更友好.简洁 ...
- OpenStack中的Multipath faulty device的成因及解决(part 1)
| 版权:本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接.如有问题,可以邮件:wangxu198709@gmail.com 简介: Multip ...
- #ASP.NET 自制免费.NET代码生成器KevinCodeBuilder
简单的.NET三层架构会有很多重复的代码,如果手敲会比较浪费时间.前段时间在互联网找了下.NET的代码生成器,发现要么太复杂甚至生成的代码会报错,要么要收费而且效果不是自己想要的. 所以,干脆自己做一 ...
- javascript研究小组知识库
http://hzjavaeyer.group.iteye.com/group/wiki?category_id=0
- Codeforces 1088E Ehab and a component choosing problem
Ehab and a component choosing problem 如果有多个连接件那么这几个连接件一定是一样大的, 所以我们先找到值最大的连通块这个肯定是分数的答案. dp[ i ]表示对于 ...
- Win7如何解决telnet不是内部或外部命令的方案!
https://jingyan.baidu.com/article/7908e85c6ec355af491ad265.html Telnet用于远程操作互联网中的设备或终端计算机服务器,可以有效的减少 ...
- 网页图表Highcharts实践教程标之添加题副标题版权信息
网页图表Highcharts实践教程标之添加题副标题版权信息 Highcharts辅助元素 辅助元素图表的非必要元素,如标题.版权信息.标签.载入动态.它们不和图表数据发生关联,只是额外说明一些基本信 ...