关于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. 使用AS3输出ByteArray为16进制

    package { import flash.utils.ByteArray; /** * 输出ByteArray为16进制 * @author Rise */ public class Byte2H ...

  2. Java基础知识学习(一)

    部门接了新项目,后台使用Java框架play framework,前端是html,前后台通过rest交互,能够支持多端的互联网架构. 因为之前没有Java基础,前端使用的也很少,决定深入学习一下Jav ...

  3. json与jsonp的区别

    前言 由于Sencha Touch 2这种开发模式的特性,基本决定了它原生的数据交互行为几乎只能通过AJAX来实现. 当然了,通过调用强大的PhoneGap插件然后打包,你可以实现100%的Socke ...

  4. (转)教你记住ASP.NET WebForm页面的生命周期

    对于ASP.NET Webform的开发者,理解ASP.NET Webform的页面生命周期是非常重要的.主要是为了搞明白在哪里放置特定的方法和在何时设置各种页面属性.但是记忆和理解页面生命周期里提供 ...

  5. 解决由OpenShift自带的APC加速器造成的代码无法及时生效的问题

    如果你在使用你的Openshift时出现了这样的问题,那就说明APC加速器导致了此故障 1.上传后的代码运行效果没有变化 2.Wordpress翻来覆去自己重复升级一个版本(←Wordpress在自嗨 ...

  6. ios app响应background,foreground 事件实现

    1 通过AppDelegate 实现 App进入后台事件方法 - (void)applicationDidEnterBackground:(UIApplication *)application AP ...

  7. .net开发windows服务小结

        今天学习了在.net下创建一个windows服务,总结一下学习心得.     开发环境:visual studio 2012   一.编写程序 (1)创建一个空解决方法 (2)添加一个控制台应 ...

  8. Ngigx+Tomcat配置动静分离,负载均衡

    由于公司使用过Ngnix,对于刚接触Nginx来说,感觉有些好奇,于是研究了下. 本人在windows下使用的版本是nginx-1.8.1: 1. 启动Ngnix 双击nginx-1.8.1文件夹中n ...

  9. SQL与NoSQL(关系型与非关系型)数据库的区别

    永远正确的经典答案依然是:具体问题具体分析. 数据表VS.数据集 关系型和非关系型数据库的主要差异是数据存储的方式.关系型数据天然就是表格式的,因此存储在数据表的行和列中.数据表可以彼此关联协作存储, ...

  10. dotNET使用DRPC远程调用运行在Storm上的Topology

    Distributed RPC(DRPC)是Storm构建在Thrift协议上的RPC的实现,DRPC使得你可以通过多种语言远程的使用Storm集群的计算能力.DRPC并非Storm的基础特性,但它确 ...