关于PropertyGrid控件的详细用法请参考文献:

1、C# PropertyGrid控件应用心得

2、C#自定义PropertyGrid属性

首先定义一个要在下拉框显示的控件:

using System;
using System.Windows.Forms;
namespace Simon.WinForms.Examples.PropertyGrid
{
public class EditorControl : UserControl
{
public EditorControl()
{
this.label1 = new System.Windows.Forms.Label();
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(, );
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(, );
this.label1.TabIndex = ;
this.label1.Text = "名称:"; this.comboBox1 = new System.Windows.Forms.ComboBox();
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Items.AddRange(new object[] {
"名称一",
"名称二",
"名称三",
"名称四"});
this.comboBox1.Location = new System.Drawing.Point(, );
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(, );
this.comboBox1.TabIndex = ;
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged); this.SuspendLayout();
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.label1);
this.Name = "EditorControl";
this.Size = new System.Drawing.Size(, );
this.ResumeLayout(false);
this.PerformLayout();
} private Label label1;
private ComboBox comboBox1; public string result = "";
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
result = comboBox1.SelectedItem.ToString();
}
}
}

从System.Drawing.Design.UITypeEditor继承一个自定义属性编辑管理器类,参考如下:

using System.Drawing.Design;
using System.Windows.Forms.Design; namespace Simon.WinForms.Examples.PropertyGrid
{
public class Editor : UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
{
// 编辑属性值时,在右侧显示...更多按钮
return UITypeEditorEditStyle.Modal;
} public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
{
var edSvc = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
if (edSvc != null)
{
var popedControl = new EditorControl();
// 还有ShowDialog这种方式,可以弹出一个窗体来进行编辑
edSvc.DropDownControl(popedControl);
value = popedControl.result;
}
return base.EditValue(context, provider, value);
}
}
}

定义一个使用PropertyGrid显示属性的类型。

using System.ComponentModel;  

namespace Simon.WinForms.Examples.PropertyGrid
{
public class ShowedClass
{
[DisplayName("名称")]
[Editor(typeof(Editor), typeof(System.Drawing.Design.UITypeEditor))]
public string Name { get; set; } [Editor(typeof(Editor), typeof(System.Drawing.Design.UITypeEditor))]
public string Description { get; set; }
}
}

在窗体上放好PropertyGrid,然后把你的类实例化后让PropertyGrid来显示设置就可以看到效果了。

propertyGrid1.SelectedObject = new ShowedClass() { Name="我没名字"};  

原文连接:C# 如何定义让PropertyGrid控件显示[...]按钮,并且点击后以下拉框形式显示自定义控件编辑属性值

C# 如何定义让PropertyGrid控件显示[...]按钮,并且点击后以下拉框形式显示自定义控件编辑属性值的更多相关文章

  1. 简述Object(ActiveX)控件遮挡Dialog、select下拉框的解决办法

    1.背景 最近在做项目的过程中,我们使用了Object控件,但是同时在上面写了一个select下拉框,因此每次点击下拉框的时候我们会发现,下拉框的部分内容被Object控件给遮挡了,调查研究后发现,我 ...

  2. 自定义SWT控件一之自定义单选下拉框

    一.自定义下拉控件 自定义的下拉框,是自定义样式的,其中的下拉框使用的是独立的window,非复选框的下拉框双击单机其它区域或选择完之后,独立window构成的下拉框会自动消失. package co ...

  3. bootstrap-table之通用方法( 时间控件,导出,动态下拉框, 表单验证 ,选中与获取信息)

    1.bootstrap-table 单击单行选中 $('#gzrwTable').on('click-row.bs.table', function(e, row, $element) { $('.s ...

  4. 自定义SWT控件三之搜索功能下拉框

    3.搜索功能下拉弹出框 package com.view.control.select; import java.util.ArrayList; import java.util.LinkedList ...

  5. WinForm窗体PropertyGrid控件的使用

    使用过 Microsoft Visual Basic 或 Microsoft Visual Studio .NET的朋友,一定使用过属性浏览器来浏览.查看或编辑一个或多个对象的属性..NET 框架 P ...

  6. PropertyGrid控件由浅入深(二):基础用法

    目录 PropertyGrid控件由浅入深(一):文章大纲 PropertyGrid控件由浅入深(二):基础用法 控件的外观构成 控件的外观构成如下图所示: PropertyGrid控件包含以下几个要 ...

  7. C# PropertyGrid控件应用心得

    何处使用 PropertyGrid 控件 在应用程序中的很多地方,您都可以使用户与 PropertyGrid 进行交互,从而获得更丰富的编辑体验.例如,某个应用程序包含多个用户可以设置的“设置”或选项 ...

  8. C# PropertyGrid控件应用心得 【转】

    源文 : http://blog.csdn.net/luyifeiniu/article/details/5426960 c#stringattributesobjectmicrosoftclass ...

  9. PropertyGrid控件由浅入深(一):文章大纲

    Winform中PropertyGrid控件是一个非常好用的对象属性编辑工具,对于Key-Value形式的数据的处理也是非常的好用. 因为Property控件设计良好,在很小的空间内可以展示很多的内容 ...

随机推荐

  1. eclipse如何优化构建的速度(Building)

    小Alan在平时的开发中很喜欢做一件事,那就是盯着eclipse的状态栏,看着Build Workspace的进度条一点一点慢慢的走,小Alan坐在电脑面前默默不想说话,就是心中总是有十万匹马在奔腾, ...

  2. IIS和tomcat共用80端口

    IIS和tomcat共用80端口 很多机器都需要同时使用tomcat和iis两个服务器以部署不同的网站,而解决共用80端口的问题也经常遇到,今天实际操作了一回,以下是具体步骤: 实现tomcat和ii ...

  3. Redis客户端开发包:Jedis学习-入门

    添加Jedis依赖 我们可以使用以下三种方式来添加Jedis依赖. 1.下载jar文件 从http://search.maven.org/下载最近的jedis包和Apache Commons Pool ...

  4. 每日Scrum(9)

    今天我们小组进行了软件的测试和界面的美化,特别是在主界面美化方面下了一些功夫,找了很多图片,把格式也处理的很完美,符合界面的一个框架,看起来,美观多了,至此,软件的beta版是基本完成了.

  5. sql server 小记——分区表(上)

    我们知道很多事情都存在一个分治的思想,同样的道理我们也可以用到数据表上,当一个表很大很大的时候,我们就会想到将表拆 分成很多小表,查询的时候就到各个小表去查,最后进行汇总返回给调用方来加速我们的查询速 ...

  6. Java api 入门教程 之 JAVA的文件操作

    I/O类使用 由于在IO操作中,需要使用的数据源有很多,作为一个IO技术的初学者,从读写文件开始学习IO技术是一个比较好的选择.因为文件是一种常见的数据源,而且读写文件也是程序员进行IO编程的一个基本 ...

  7. SqlServer时间格式化

    最近用的SqlServer比较多,时间格式化老是忘记,现整理如下:(来源于网上,具体来源地址忘记了,归根到底MSDN吧) SELECT CONVERT(varchar(50), GETDATE(), ...

  8. jquery常用方法

    一.多个按钮绑定同一事件 $("#index_svip,#index_svip_renew").click(function() { seajs.use(['svipLayer'] ...

  9. SQL Learning Notes

    Sams Teach Yourself SQL in 10 Minutes

  10. NOIP 2008提高组第三题题解by rLq

    啊啊啊啊啊啊今天已经星期三了吗 那么,来一波题解吧 本题地址http://www.luogu.org/problem/show?pid=1006 传纸条 题目描述 小渊和小轩是好朋友也是同班同学,他们 ...