C# 如何定义让PropertyGrid控件显示[...]按钮,并且点击后以下拉框形式显示自定义控件编辑属性值
关于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控件显示[...]按钮,并且点击后以下拉框形式显示自定义控件编辑属性值的更多相关文章
- 简述Object(ActiveX)控件遮挡Dialog、select下拉框的解决办法
1.背景 最近在做项目的过程中,我们使用了Object控件,但是同时在上面写了一个select下拉框,因此每次点击下拉框的时候我们会发现,下拉框的部分内容被Object控件给遮挡了,调查研究后发现,我 ...
- 自定义SWT控件一之自定义单选下拉框
一.自定义下拉控件 自定义的下拉框,是自定义样式的,其中的下拉框使用的是独立的window,非复选框的下拉框双击单机其它区域或选择完之后,独立window构成的下拉框会自动消失. package co ...
- bootstrap-table之通用方法( 时间控件,导出,动态下拉框, 表单验证 ,选中与获取信息)
1.bootstrap-table 单击单行选中 $('#gzrwTable').on('click-row.bs.table', function(e, row, $element) { $('.s ...
- 自定义SWT控件三之搜索功能下拉框
3.搜索功能下拉弹出框 package com.view.control.select; import java.util.ArrayList; import java.util.LinkedList ...
- WinForm窗体PropertyGrid控件的使用
使用过 Microsoft Visual Basic 或 Microsoft Visual Studio .NET的朋友,一定使用过属性浏览器来浏览.查看或编辑一个或多个对象的属性..NET 框架 P ...
- PropertyGrid控件由浅入深(二):基础用法
目录 PropertyGrid控件由浅入深(一):文章大纲 PropertyGrid控件由浅入深(二):基础用法 控件的外观构成 控件的外观构成如下图所示: PropertyGrid控件包含以下几个要 ...
- C# PropertyGrid控件应用心得
何处使用 PropertyGrid 控件 在应用程序中的很多地方,您都可以使用户与 PropertyGrid 进行交互,从而获得更丰富的编辑体验.例如,某个应用程序包含多个用户可以设置的“设置”或选项 ...
- C# PropertyGrid控件应用心得 【转】
源文 : http://blog.csdn.net/luyifeiniu/article/details/5426960 c#stringattributesobjectmicrosoftclass ...
- PropertyGrid控件由浅入深(一):文章大纲
Winform中PropertyGrid控件是一个非常好用的对象属性编辑工具,对于Key-Value形式的数据的处理也是非常的好用. 因为Property控件设计良好,在很小的空间内可以展示很多的内容 ...
随机推荐
- 网站错误记录:A transport-level error has occurred when sending the request to the server.
今天查看公司项目的日志文件,发现有这个错误:A transport-level error has occurred when sending the request to the server. 感 ...
- MySQL主主双机负载均衡
MySQL双机主主架构,其上辅以负载均衡设备,可以实现mysql数据库的负载均衡高性能和高可用性,负载均衡设备可以根据算法将数据库操作的负 载平均分到两台MySQL服务器上,这样对于每台服务器来说工作 ...
- <a href>传参的中文乱码问题
版权声明:本文为博主半原创文章,未经博主允许不得不转载时允许转载 :) 当需要href进行传参,参数为中文时,会出现乱码问题,最简单的方法是: 传入的值首先用escape()进行转码,然后在取值页面用 ...
- Java编译器如何生成重载和覆盖方法代码
下面是一个很简单的例子,关于Java中的多态:方法重载和方法覆盖: 多态指的是方法在不同的时刻表现出不同的形式:在编译期间,这被叫做方法重载:方法重载允许相关的方法被同一个方法名字调用,这有时候被叫做 ...
- Asp.net MVC使用Filter解除Session, Cookie等依赖
本文,介绍了Filter在MVC请求的生命周期中的作用和角色,以及Filter的一些常用应用场景. 同时针对MVC中的对于Session,Cookie等的依赖,如何使用Filter解依赖. 如果大家有 ...
- Java并发之BlockingQueue 阻塞队列(ArrayBlockingQueue、LinkedBlockingQueue、DelayQueue、PriorityBlockingQueue、SynchronousQueue)
package com.thread.test.thread; import java.util.Random; import java.util.concurrent.*; /** * Create ...
- CStdioFile CString 读写中文
TCHAR* old_locale = _tcsdup( _tsetlocale(LC_CTYPE,NULL) ); _tsetlocale( LC_CTYPE, _T("chs" ...
- linux下使用Apache+php实现留言板功能的网站
一.首先我们的linux服务器上要安装Apache和php 请参考:http://www.cnblogs.com/dagege/p/5949620.html 二.关闭防火墙服务,关闭selinux 请 ...
- [转]Asp.net MVC使用Filter解除Session, Cookie等依赖
本文转自:http://www.cnblogs.com/JustRun1983/p/3279139.html 本文,介绍了Filter在MVC请求的生命周期中的作用和角色,以及Filter的一些常用应 ...
- cuda中thread id
//////////////////////////////////////////////////////////////////////////// // // Copyright 1993-20 ...