propertygrid
网络转载,原文来自:http://blog.csdn.net/lxping1012/article/details/7073944
最近用到了propertygrid,原来从来没用到过,拿在手里,一头雾水,经过一段时间研究后,大概理解了Property的使用方法,下面仔细剖析一下。
PropertyGrid控件就是Visual Studio开发工具里面的属性浏览器,我们在VS里面可以通过属性浏览器查看,修改控件的属性,并主要通过使用反射来检索项目的属性。
一.如何显示属性
1)普通显示
在PropertyGrid中显示属性很容易,我们可以直接给propertyGrid1.SelectedObject属性赋值,SelectObject属性可以获取或设置当前选定的对象,数据类型为object,这就意味着我们可以直接将一个对象赋给它。针对一个对象,它会将对象中的所有公共属性显示在PropertyGrid上。假如我们定义一个Station类,如下
[csharp]view plaincopy
- publicclassStation
- {
- privatestring_StationName;
- privatedouble_Lon=103;
- privatedouble_Lat=38;
- privatecolor_color;
- privatestring_file=string.empty;
- privateFont_font;
- publicstringFileName
- {
- get{return_file;}
- set{_file=value;}
- }
- publicColorColor
- {
- get{return_color;}
- set{_color=value;}
- }
- publicFontFont
- {
- get{return_font;}
- set{_font=value;}
- }
- publicstringStationName
- {
- get{return_StationName;}
- set{_StationName=value;}
- }
- publicdoubleLon
- {
- get{return_Lon;}
- set{_Lon=value;}
- }
- publicdoubleLat
- {
- get{return_Lat;}
- set{_Lat=value;}
- }
- }
[csharp]view plaincopy
- publicclassStation
- {
- privatestring_StationName;
- privatedouble_Lon=103;
- privatedouble_Lat=38;
- privateColor_color;
- privatestring_file=string.Empty;
- privateFont_font;
- publicstringFileName
- {
- get{return_file;}
- set{_file=value;}
- }
- publicColorColor
- {
- get{return_color;}
- set{_color=value;}
- }
- publicFontFont
- {
- get{return_font;}
- set{_font=value;}
- }
- publicstringStationName
- {
- get{return_StationName;}
- set{_StationName=value;}
- }
- publicdoubleLon
- {
- get{return_Lon;}
- set{_Lon=value;}
- }
- publicdoubleLat
- {
- get{return_Lat;}
- set{_Lat=value;}
- }
- }
然后在窗体中拖拉一个PropertyGrid控件propertygrid1,在Form_load中代码如下
[csharp]view plaincopy
- privatevoidForm1_Load(objectsender,EventArgse)
- {
- Stations=newStation();
- propertygrid1.SelectObject=s;
- }
[csharp]view plaincopy
- privatevoidForm1_Load(objectsender,EventArgse)
- {
- Stations=newStation();
- propertygrid1.SelectObject=s;
- }
我们看到属性名显示都是英文,那样很不方便阅读如果我们像显示中文,该如何实现呢?
更改了显示方式
要更改某些属性的显示方式,您可以对这些属性应用不同的特性。特性是用于为类型、字段、方法和属性等编程元素添加批注的声明标记,在运行时可以使用反射对其进行检索。下面列出了其中的一部分:
DescriptionAttribute- 设置显示在属性下方说明帮助窗格中的属性文本。这是一种为活动属性(即具有焦点的属性)提供帮助文本的有效方法。
CategoryAttribute- 设置属性在网格中所属的类别。当您需要将属性按类别名称分组时,此特性非常有用。如果没有为属性指定类别,该属性将被分配给杂项类别。可以将此特性应用于所有属性。BrowsableAttribute– 表示是否在网格中显示属性。此特性可用于在网格中隐藏属性。默认情况下,公共属性始终显示在网格中。
ReadOnlyAttribute– 表示属性是否为只读。此特性可用于禁止在网格中编辑属性。默认情况下,带有 get 和 set 访问函数的公共属性在网格中是可以编辑的。
DefaultValueAttribute– 表示属性的默认值。如果希望为属性提供默认值,然后确定该属性值是否与默认值相同,则可使用此特性。可以将此特性应用于所有属性。
DefaultPropertyAttribute– 表示类的默认属性。在网格中选择某个类时,将首先突出显示该类的默认属性。
下面我们在Station类中的属性Lon上方添加[CategoryAttribute("坐标"),displayNameAttribute("经度")],效果如下:
如果想要在属性表中添加颜色选择和字体选择那是很容易一件事,可以在Station类中添加Color类型属性,和Font类型属性,绑定后,就可以进行颜色选择和字体选择了,代码在Station中已经实现。
2)自定义显示
我们可以看出这种上面这种显示属性方法并不够灵活,我们不能方便的及时增加或者删除属性。
//属性表管理类
[csharp]view plaincopy
- <spanstyle="font-size:13px;">publicclassPropertyManageCls:CollectionBase,ICustomTypeDescriptor
- {
- publicvoidAdd(Propertyvalue)
- {
- intflag=-1;
- if(value!=null)
- {
- if(base.List.Count>0)
- {
- IList<Property>mList=newList<Property>();
- for(inti=0;i<base.List.Count;i++)
- {
- Propertyp=base.List[i]asProperty;
- if(value.Name==p.Name)
- {
- flag=i;
- }
- mList.Add(p);
- }
- if(flag==-1)
- {
- mList.Add(value);
- }
- base.List.Clear();
- foreach(PropertypinmList)
- {
- base.List.Add(p);
- }
- }
- else
- {
- base.List.Add(value);
- }
- }
- }
- publicvoidRemove(Propertyvalue)
- {
- if(value!=null&&base.List.Count>0)
- base.List.Remove(value);
- }
- publicPropertythis[intindex]
- {
- get
- {
- return(Property)base.List[index];
- }
- set
- {
- base.List[index]=(Property)value;
- }
- }
- #regionICustomTypeDescriptor成员
- publicAttributeCollectionGetAttributes()
- {
- returnTypeDescriptor.GetAttributes(this,true);
- }
- publicstringGetClassName()
- {
- returnTypeDescriptor.GetClassName(this,true);
- }
- publicstringGetcomponentname()
- {
- returnTypeDescriptor.GetComponentName(this,true);
- }
- publicTypeConverterGetConverter()
- {
- returnTypeDescriptor.GetConverter(this,true);
- }
- publicEventDescriptorGetDefaultEvent()
- {
- returnTypeDescriptor.GetDefaultEvent(this,true);
- }
- publicPropertyDescriptorGetDefaultProperty()
- {
- returnTypeDescriptor.GetDefaultProperty(this,true);
- }
- publicobjectGetEditor(TypeeditorBaseType)
- {
- returnTypeDescriptor.GetEditor(this,editorBaseType,true);
- }
- publicEventDescriptorCollectionGetEvents(Attribute[]attributes)
- {
- returnTypeDescriptor.GetEvents(this,attributes,true);
- }
- publicEventDescriptorCollectionGetEvents()
- {
- returnTypeDescriptor.GetEvents(this,true);
- }
- publicPropertyDescriptorCollectionGetProperties(Attribute[]attributes)
- {
- PropertyDescriptor[]newProps=newPropertyDescriptor[this.Count];
- for(inti=0;i<this.Count;i++)
- {
- Propertyprop=(Property)this[i];
- newProps[i]=newCustomPropertyDescriptor(refprop,attributes);
- }
- returnnewPropertyDescriptorCollection(newProps);
- }
- publicPropertyDescriptorCollectionGetProperties()
- {
- returnTypeDescriptor.GetProperties(this,true);
- }
- publicobjectGetPropertyOwner(PropertyDescriptorpd)
- {
- returnthis;
- }
- #endregion
- }
- //属性类
- publicclassProperty
- {
- privatestring_name=string.Empty;
- privateobject_value=null;
- privatebool_readonly=false;
- privatebool_visible=true;
- privatestring_category=string.Empty;
- TypeConverter_converter=null;
- object_editor=null;
- privatestring_displayname=string.Empty;
- publicProperty(stringsName,objectsValue)
- {
- this._name=sName;
- this._value=sValue;
- }
- publicProperty(stringsName,objectsValue,boolsReadonly,boolsVisible)
- {
- this._name=sName;
- this._value=sValue;
- this._readonly=sReadonly;
- this._visible=sVisible;
- }
- publicstringName//获得属性名
- {
- get
- {
- return_name;
- }
- set
- {
- _name=value;
- }
- }
- publicstringDisplayName//属性显示名称
- {
- get
- {
- return_displayname;
- }
- set
- {
- _displayname=value;
- }
- }
- publicTypeConverterConverter//类型转换器,我们在制作下拉列表时需要用到
- {
- get
- {
- return_converter;
- }
- set
- {
- _converter=value;
- }
- }
- publicstringCategory//属性所属类别
- {
- get
- {
- return_category;
- }
- set
- {
- _category=value;
- }
- }
- publicobjectValue//属性值
- {
- get
- {
- return_value;
- }
- set
- {
- _value=value;
- }
- }
- publicboolReadOnly//是否为只读属性
- {
- get
- {
- return_readonly;
- }
- set
- {
- _readonly=value;
- }
- }
- publicboolVisible//是否可见
- {
- get
- {
- return_visible;
- }
- set
- {
- _visible=value;
- }
- }
- publicvirtualobjectEditor//属性编辑器
- {
- get
- {
- return_editor;
- }
- set
- {
- _editor=value;
- }
- }
- }
- publicclassCustomPropertyDescriptor:PropertyDescriptor
- {
- Propertym_Property;
- publicCustomPropertyDescriptor(refPropertymyProperty,Attribute[]attrs)
- :base(myProperty.Name,attrs)
- {
- m_Property=myProperty;
- }
- #regionPropertyDescriptor重写方法
- publicoverrideboolCanResetValue(objectcomponent)
- {
- returnfalse;
- }
- publicoverrideTypeComponentType
- {
- get
- {
- returnnull;
- }
- }
- publicoverrideobjectGetValue(objectcomponent)
- {
- returnm_Property.Value;
- }
- publicoverridestringDescription
- {
- get
- {
- returnm_Property.Name;
- }
- }
- publicoverridestringCategory
- {
- get
- {
- returnm_Property.Category;
- }
- }
- publicoverridestringDisplayName
- {
- get
- {
- returnm_Property.DisplayName!=""?m_Property.DisplayName:m_Property.Name;
- }
- }
- publicoverrideboolIsReadOnly
- {
- get
- {
- returnm_Property.ReadOnly;
- }
- }
- publicoverridevoidResetValue(objectcomponent)
- {
- //Havetoimplement
- }
- publicoverrideboolShouldserializeValue(objectcomponent)
- {
- returnfalse;
- }
- publicoverridevoidSetValue(objectcomponent,objectvalue)
- {
- m_Property.Value=value;
- }
- publicoverrideTypeConverterConverter
- {
- get
- {
- returnm_Property.Converter;
- }
- }
- publicoverrideTypePropertyType
- {
- get{returnm_Property.Value.GetType();}
- }
- publicoverrideobjectGetEditor(TypeeditorBaseType)
- {
- returnm_Property.Editor==null?base.GetEditor(editorBaseType):m_Property.Editor;
- }
- #endregion
- }</span>
[csharp]view plaincopy
- <spanstyle="font-size:13px;"data-filtered="filtered">publicclassPropertyManageCls:CollectionBase,ICustomTypeDescriptor
- {
- publicvoidAdd(Propertyvalue)
- {
- intflag=-1;
- if(value!=null)
- {
- if(base.List.Count>0)
- {
- IList<Property>mList=newList<Property>();
- for(inti=0;i<base.List.Count;i++)
- {
- Propertyp=base.List[i]asProperty;
- if(value.Name==p.Name)
- {
- flag=i;
- }
- mList.Add(p);
- }
- if(flag==-1)
- {
- mList.Add(value);
- }
- base.List.Clear();
- foreach(PropertypinmList)
- {
- base.List.Add(p);
- }
- }
- else
- {
- base.List.Add(value);
- }
- }
- }
- publicvoidRemove(Propertyvalue)
- {
- if(value!=null&&base.List.Count>0)
- base.List.Remove(value);
- }
- publicPropertythis[intindex]
- {
- get
- {
- return(Property)base.List[index];
- }
- set
- {
- base.List[index]=(Property)value;
- }
- }
- #regionICustomTypeDescriptor成员
- publicAttributeCollectionGetAttributes()
- {
- returnTypeDescriptor.GetAttributes(this,true);
- }
- publicstringGetClassName()
- {
- returnTypeDescriptor.GetClassName(this,true);
- }
- publicstringGetComponentName()
- {
- returnTypeDescriptor.GetComponentName(this,true);
- }
- publicTypeConverterGetConverter()
- {
- returnTypeDescriptor.GetConverter(this,true);
- }
- publicEventDescriptorGetDefaultEvent()
- {
- returnTypeDescriptor.GetDefaultEvent(this,true);
- }
- publicPropertyDescriptorGetDefaultProperty()
- {
- returnTypeDescriptor.GetDefaultProperty(this,true);
- }
- publicobjectGetEditor(TypeeditorBaseType)
- {
- returnTypeDescriptor.GetEditor(this,editorBaseType,true);
- }
- publicEventDescriptorCollectionGetEvents(Attribute[]attributes)
- {
- returnTypeDescriptor.GetEvents(this,attributes,true);
- }
- publicEventDescriptorCollectionGetEvents()
- {
- returnTypeDescriptor.GetEvents(this,true);
- }
- publicPropertyDescriptorCollectionGetProperties(Attribute[]attributes)
- {
- PropertyDescriptor[]newProps=newPropertyDescriptor[this.Count];
- for(inti=0;i<this.Count;i++)
- {
- Propertyprop=(Property)this[i];
- newProps[i]=newCustomPropertyDescriptor(refprop,attributes);
- }
- returnnewPropertyDescriptorCollection(newProps);
- }
- publicPropertyDescriptorCollectionGetProperties()
- {
- returnTypeDescriptor.GetProperties(this,true);
- }
- publicobjectGetPropertyOwner(PropertyDescriptorpd)
- {
- returnthis;
- }
- #endregion
- }
- //属性类
- publicclassProperty
- {
- privatestring_name=string.Empty;
- privateobject_value=null;
- privatebool_readonly=false;
- privatebool_visible=true;
- privatestring_category=string.Empty;
- TypeConverter_converter=null;
- object_editor=null;
- privatestring_displayname=string.Empty;
- publicProperty(stringsName,objectsValue)
- {
- this._name=sName;
- this._value=sValue;
- }
- publicProperty(stringsName,objectsValue,boolsReadonly,boolsVisible)
- {
- this._name=sName;
- this._value=sValue;
- this._readonly=sReadonly;
- this._visible=sVisible;
- }
- publicstringName//获得属性名
- {
- get
- {
- return_name;
- }
- set
- {
- _name=value;
- }
- }
- publicstringDisplayName//属性显示名称
- {
- get
- {
- return_displayname;
- }
- set
- {
- _displayname=value;
- }
- }
- publicTypeConverterConverter//类型转换器,我们在制作下拉列表时需要用到
- {
- get
- {
- return_converter;
- }
- set
- {
- _converter=value;
- }
- }
- publicstringCategory//属性所属类别
- {
- get
- {
- return_category;
- }
- set
- {
- _category=value;
- }
- }
- publicobjectValue//属性值
- {
- get
- {
- return_value;
- }
- set
- {
- _value=value;
- }
- }
- publicboolReadOnly//是否为只读属性
- {
- get
- {
- return_readonly;
- }
- set
- {
- _readonly=value;
- }
- }
- publicboolVisible//是否可见
- {
- get
- {
- return_visible;
- }
- set
- {
- _visible=value;
- }
- }
- publicvirtualobjectEditor//属性编辑器
- {
- get
- {
- return_editor;
- }
- set
- {
- _editor=value;
- }
- }
- }
- publicclassCustomPropertyDescriptor:PropertyDescriptor
- {
- Propertym_Property;
- publicCustomPropertyDescriptor(refPropertymyProperty,Attribute[]attrs)
- :base(myProperty.Name,attrs)
- {
- m_Property=myProperty;
- }
- #regionPropertyDescriptor重写方法
- publicoverrideboolCanResetValue(objectcomponent)
- {
- returnfalse;
- }
- publicoverrideTypeComponentType
- {
- get
- {
- returnnull;
- }
- }
- publicoverrideobjectGetValue(objectcomponent)
- {
- returnm_Property.Value;
- }
- publicoverridestringDescription
- {
- get
- {
- returnm_Property.Name;
- }
- }
- publicoverridestringCategory
- {
- get
- {
- returnm_Property.Category;
- }
- }
- publicoverridestringDisplayName
- {
- get
- {
- returnm_Property.DisplayName!=""?m_Property.DisplayName:m_Property.Name;
- }
- }
- publicoverrideboolIsReadOnly
- {
- get
- {
- returnm_Property.ReadOnly;
- }
- }
- publicoverridevoidResetValue(objectcomponent)
- {
- //Havetoimplement
- }
- publicoverrideboolShouldSerializeValue(objectcomponent)
- {
- returnfalse;
- }
- publicoverridevoidSetValue(objectcomponent,objectvalue)
- {
- m_Property.Value=value;
- }
- publicoverrideTypeConverterConverter
- {
- get
- {
- returnm_Property.Converter;
- }
- }
- publicoverrideTypePropertyType
- {
- get{returnm_Property.Value.GetType();}
- }
- publicoverrideobjectGetEditor(TypeeditorBaseType)
- {
- returnm_Property.Editor==null?base.GetEditor(editorBaseType):m_Property.Editor;
- }
- #endregion
- }</span>
下面我们来看看该如何使用,我们仍然在Form_load中添加代码如下:
[csharp]view plaincopy
- <spanstyle="font-size:13px;">PropertyManageClspmc=newPropertyManageCls();
- Propertypp=newProperty("ID","1",false,true);
- pp.Category="基本信息";
- pp.DisplayName="我的ID";
- pmc.Add(pp);
- propertyGrid1.SelectObject=pmc;</span>
[csharp]view plaincopy
- <spanstyle="font-size:13px;"data-filtered="filtered">PropertyManageClspmc=newPropertyManageCls();
- Propertypp=newProperty("ID","1",false,true);
- pp.Category="基本信息";
- pp.DisplayName="我的ID";
- pmc.Add(pp);
- propertyGrid1.SelectObject=pmc;</span>
我们可以看到上面的属性显示很简单,如果想要自定义一个下拉框,或者有一个路径选择的该怎么办呢。
1)类型转换器
要实现下拉框的方法:使用类型转换器,需要继承与TypeConverter或者StringConverter,然后重写方法,代码如下:
[csharp]view plaincopy
- <spanstyle="font-size:13px;">//下拉框类型转换器
- publicclassDropDownListConverter:StringConverter
- {
- object[]m_Objects;
- publicDropDownListConverter(object[]objects)
- {
- m_Objects=objects;
- }
- publicoverrideboolGetStandardValuesSupported(ITypeDescriptorcontextcontext)
- {
- returntrue;
- }
- publicoverrideboolGetStandardValuesExclusive(ITypeDescriptorContextcontext)
- {
- returntrue;</span><spanstyle='color:rgb(0,130,0);line-height:15.39px;font-family:Consolas,"BitstreamVeraSansMono","CourierNew",Courier,monospace;font-size:14px;'>//true下拉框不可编辑</span><spanstyle="font-size:13px;">
- </span><spanstyle="font-size:13px;">
- }
- publicoverride
- System.ComponentModel.TypeConverter.StandardValuesCollectionGetStandardValues(ITypeDescriptorContextcontext)
- {
- returnnewStandardValuesCollection(m_Objects);//我们可以直接在内部定义一个数组,但并不建议这样做,这样对于下拉框的灵活//性有很大影响
- }
- }</span>
[csharp]view plaincopy
- <spanstyle="font-size:13px;"data-filtered="filtered">//下拉框类型转换器
- publicclassDropDownListConverter:StringConverter
- {
- object[]m_Objects;
- publicDropDownListConverter(object[]objects)
- {
- m_Objects=objects;
- }
- publicoverrideboolGetStandardValuesSupported(ITypeDescriptorContextcontext)
- {
- returntrue;
- }
- publicoverrideboolGetStandardValuesExclusive(ITypeDescriptorContextcontext)
- {
- returntrue;</span><spanstyle="font-family:Consolas,'BitstreamVeraSansMono','CourierNew',Courier,monospace;font-size:14px;color:#0820;line-height:15.39px;"data-filtered="filtered">//true下拉框不可编辑</span><spanstyle="font-size:13px;"data-filtered="filtered">
- </span><spanstyle="font-size:13px;"data-filtered="filtered">
- }
- publicoverride
- System.ComponentModel.TypeConverter.StandardValuesCollectionGetStandardValues(ITypeDescriptorContextcontext)
- {
- returnnewStandardValuesCollection(m_Objects);//我们可以直接在内部定义一个数组,但并不建议这样做,这样对于下拉框的灵活//性有很大影响
- }
- }</span>
我们实现了下拉框类型转换器,但该如何使用呢?
使用方法一:我们仍然以Station类作为例子,在属性上方添加标记[TypeConverter(typeof(DropDownListConverter))],但在这种情况下,我们需要预先在DropDownListConverter中定义下拉框内容。
使用方法二:这种方法我们可以在外部定义数组,使用方便,使用方法代码如下:
[csharp]view plaincopy
- <spanstyle="color:rgb(51,51,51);font-family:Arial;"><spanstyle="font-size:13px;">privatevoidForm_load(objectsender,EventArgse)
- {
- PropertyManageClspmc=newPropertyManageCls();
- string[]s=newstring[]{"1","2","3","4"};
- Propertypp=newProperty(txtname.Text,txtvalue.Text,false,true);
- pp.Category="基本信息";
- pp.DisplayName="我的ID";
- pp.Converter=newDropDownListConverter(s);//Property的Converter属性就可以设置类型转换
- pmc.Add(pp);
- propertyGrid1.SelectObject=pmc;
- }</span></span>
[csharp]view plaincopy
- <spanstyle="font-family:Arial;color:#333333;"data-filtered="filtered"><spanstyle="font-size:13px;"data-filtered="filtered">privatevoidForm_load(objectsender,EventArgse)
- {
- PropertyManageClspmc=newPropertyManageCls();
- string[]s=newstring[]{"1","2","3","4"};
- Propertypp=newProperty(txtname.Text,txtvalue.Text,false,true);
- pp.Category="基本信息";
- pp.DisplayName="我的ID";
- pp.Converter=newDropDownListConverter(s);//Property的Converter属性就可以设置类型转换
- pmc.Add(pp);
- propertyGrid1.SelectObject=pmc;
- }</span></span>
2)属性编辑器
使用属性编辑器实现路径选择:属性编辑器需要继承与UITypeEditor
[csharp]view plaincopy
- <spanstyle="font-size:13px;">//文件路径选择publicclassPropertyGridFileItem:UITypeEditor
- {
- publicoverrideUITypeEditorEditStyleGetEditStyle(System.ComponentModel.ITypeDescriptorContextcontext)
- {
- returnUITypeEditorEditStyle.Modal;
- }
- publicoverrideobjectEditValue(System.ComponentModel.ITypeDescriptorContextcontext,System.
- IServiceProviderprovider,objectvalue)
- {
- IwindowsFormsEditorServiceedSvc=
- (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
- if(edSvc!=null)
- {
- //可以打开任何特定的对话框
- OpenFileDialogdialog=newOpenFileDialog();
- dialog.AddExtension=false;
- if(dialog.ShowDialog().Equals(dialogresult.OK))
- {
- returndialog.FileName;
- }
- }
- returnvalue;
- }
- }</span>
[csharp]view plaincopy
- <spanstyle="font-size:13px;"data-filtered="filtered">//文件路径选择publicclassPropertyGridFileItem:UITypeEditor
- {
- publicoverrideUITypeEditorEditStyleGetEditStyle(System.ComponentModel.ITypeDescriptorContextcontext)
- {
- returnUITypeEditorEditStyle.Modal;
- }
- publicoverrideobjectEditValue(System.ComponentModel.ITypeDescriptorContextcontext,System.
- IServiceProviderprovider,objectvalue)
- {
- IWindowsFormsEditorServiceedSvc=
- (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
- if(edSvc!=null)
- {
- //可以打开任何特定的对话框
- OpenFileDialogdialog=newOpenFileDialog();
- dialog.AddExtension=false;
- if(dialog.ShowDialog().Equals(DialogResult.OK))
- {
- returndialog.FileName;
- }
- }
- returnvalue;
- }
- }</span>
使用方法一:以Station类为例,在属性上方添加标记[EditorAttribute(typeof(PropertyGridFileItem),
typeof(System.Drawing.Design.UITypeEditor))],然后将PropertyGrid的SelectObject等于Station实例就可以了;
使用方法二:使用方法代码如下:
[csharp]view plaincopy
- <spanstyle="font-size:13px;">privatevoidForm_load(objectsender,EventArgse)
- {
- PropertyManageClspmc=newPropertyManageCls();
- Propertypp=newProperty(txtname.Text,txtvalue.Text,false,true);
- pp.Category="基本信息";
- pp.DisplayName="我的ID";
- pp.Editor=newPropertyGridFileItem();//Property的Editor属性就可以设置属性编辑
- pmc.Add(pp);
- propertyGrid1.SelectObject=pmc;
- }</span>
[csharp]view plaincopy
- <spanstyle="font-size:13px;"data-filtered="filtered">privatevoidForm_load(objectsender,EventArgse)
- {
- PropertyManageClspmc=newPropertyManageCls();
- Propertypp=newProperty(txtname.Text,txtvalue.Text,false,true);
- pp.Category="基本信息";
- pp.DisplayName="我的ID";
- pp.Editor=newPropertyGridFileItem();//Property的Editor属性就可以设置属性编辑
- pmc.Add(pp);
- propertyGrid1.SelectObject=pmc;
- }</span>
通过以上方法我们可以满足一些基本需求想要了解更多,可以看以下链接:
PropertyGrid控件心得
http://blog.csdn.net/luyifeiniu/article/details/5426960#创建 PropertyGrid 控件
Customized display of collection data in a PropertyGrid
http://www.codeproject.com/KB/tabs/customizingcollectiondata.aspx
TypeConverter的层次结构
http://msdn.microsoft.com/en-us/library/8cexyz1e
关于PropertyGrid中属性的值动态从数据库取出
http://topic.csdn.net/u/20100827/11/5524219a-4457-4921-b8f2-b4c63bc6b016.html
动态可订制属性的 PropertyGrid
http://blog.csdn.net/akron/article/details/2750566
转自http://blog.csdn.net/lxping1012/article/details/7073944
相关阅读
本文首发于本博客 猫叔的博客,转载请申明出处 前言 感谢GY丶L粉丝的提问:属性描述器PropertyDescriptor是干嘛
官方文档:https://matplotlib.org/api/markers_api.html?highlight=marker#module-matplotlib.markers 序号 标记 说明 序号 标
但凡牛掰人物出场,都伴随着“Duang”的特技,它们会不停的加特技,加特技,加特技。CSS背景图片的background-image就是这样一位牛人,它一
示例 效果 CSS myp{ max-height:910px; overflow:auto; } myp::-webkit-scrollbar{ width:8px; hei
注:本文章转载自:http://www.33lc.com/article/7364.htmlC#中的List怎么样?List<T>类是ArrayList类的泛型等效类,该类使用大小可按需