关于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. android Activity生命周期(设备旋转、数据恢复等)与启动模式

    1.Activity生命周期     接下来将介绍 Android Activity(四大组件之一) 的生命周期, 包含运行.暂停和停止三种状态,onCreate.onStart.onResume.o ...

  2. 初步认识Hive

    初步认识Hive hive是基于Hadoop的一个数据仓库工具,可以将结构化的数据文件映射为一张数据库表,并提供简单的sql查询功能,可以将sql语句转换为MapReduce任务进行运行.其优点是学习 ...

  3. 使用Hive或Impala执行SQL语句,对存储在Elasticsearch中的数据操作

    http://www.cnblogs.com/wgp13x/p/4934521.html 内容一样,样式好的版本. 使用Hive或Impala执行SQL语句,对存储在Elasticsearch中的数据 ...

  4. Linux软件的卸载

    configure作用:是源码安装软件时配置环境用的 他根据你的配置选项和你的系统情况生成makefile文件 为make 做准备 最常用的参数: ./configure --prefix 作用: 不 ...

  5. 【JAVA】调用类中的属性

    class person { String name; int age; String like; void setName(String name) { this.name = name; } vo ...

  6. php基础系列:PHP连接MySQL数据库用到的三种API

    参考自php手册.本文没有太大意义,仅为方便自己上网查阅. 1.PHP的MySQL扩展2.PHP的mysqli扩展3.PHP数据对象(PDO) MySQL扩展函数 这是设计开发允许PHP应用与MySQ ...

  7. ARC的原理详解

    1,ARC的本质 ARC本质是NSAutoreleasePool的直接应用, @autorelease{ return UIApplicationMain(argc, argv, nil, NSStr ...

  8. Java开发之JSP行为

    一.Java Bean行文 1.重点说明 Java Bean行为是一组与Java Bean相关的行为,包括useBean行为.setProperty行为.getProperty行为等.Java Bea ...

  9. ExtJs4 笔记(14) layout 布局

    作者:李盼(Lipan)出处:[Lipan] (http://www.cnblogs.com/lipan/)版权声明:本文的版权归作者与博客园共有.转载时须注明本文的详细链接,否则作者将保留追究其法律 ...

  10. 阿里云+wordpress搭建个人博客网站【小白专用的图文教程】

    [声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4 ...