PropertyGrid Usage (Hanhua Attribute)

xiaoxiao2021-03-06  15

Some friends, I am sure I have to use the properties of the property to Chinese in PropertyGrid to take the habit of our Chinese.

In fact, this Chinese, MS is supported: Please look at the code below, you only need Copy, then do the parent class of your log, then join Chinese on your vision, you will get it. Everything is so simple:

#Region All base classes of the object to be placed in PropertyGIRD.

Public Class BaseObject: icustomTypedScriptor {Private propertyDescriptorCollection globalizedprops;

Public string getclassname () {return type type (this, true);}

Public AttributeCollection GetAttributes () {Return TypedScriptor.getattributes (this, true);}

Public string getcomponentname () {return typedscriptor.getComponentName (this, true);}

Public TypeConverter getConverter () {Return TypeScriptor.getConverter (this, true);}

Public EventDescriptor getDefaultevent () {return typedscriptor.getDefault (this, true);}

Public propertyDescriptor getDefaultproperty () {return typeDescriptor.getDefaultproperty (this, true);

Public Object Getitor (Type EditorBaseType) {Return Typedescriptor.GetEtEditor (this, editorbasetype, true);}

Public EventDescriptorCollection getEvents (attribute [] attributes) {Return TypedScriptor.getevents (this, attributes, true);}

Public EventDescriptorCollection getEvents () {return typedscriptor.getevents (this, true);}

public PropertyDescriptorCollection GetProperties (Attribute [] attributes) {if (globalizedProps == null) {PropertyDescriptorCollection baseProps = TypeDescriptor.GetProperties (this, attributes, true);

Globalizedprops = New PropertyDescriptorCollection (null);

Foreach (PropertyDescriptor oprop in baseprops) {GlobalizedProps.add (New BasePropertyDescriptor (OPROP));}} Return GlobalizedProps;

public PropertyDescriptorCollection GetProperties () {if (globalizedProps == null) {PropertyDescriptorCollection baseProps = TypeDescriptor.GetProperties (this, true); globalizedProps = new PropertyDescriptorCollection (null); foreach (PropertyDescriptor oProp in baseProps) {globalizedProps.Add (new BasePropertyDescriptor (oProp )));}} Return globalizedprops;

Public Object GetPropertyOwner (PropertyDescriptor Pd) {Return this;}} #ENDREGION

#Region So to rewrite the depiction of the object in PropertyGIRD

public class BasePropertyDescriptor: PropertyDescriptor {private PropertyDescriptor basePropertyDescriptor; public BasePropertyDescriptor (PropertyDescriptor basePropertyDescriptor): base (basePropertyDescriptor) {this.basePropertyDescriptor = basePropertyDescriptor;}

Public Override Bool CanreSetValue (Object Component) {Return BasepropertyDescriptor.canResetValue (Component);

Public override type componenttype {get {return basepropertydescriptor.ComponentType;}}

public override string DisplayName {get {string svalue = ""; foreach (Attribute attribute in this.basePropertyDescriptor.Attributes) {if (attribute is showChinese) {svalue = attribute.ToString (); break;}} if (svalue == " ") Return this.BasePropertyDescriptor.name; else returnis svalue;}}

Public override string description {get {return this.basepropertydescriptor.description;}}

Public override Object getValue (Object Component) {Return this.basepropertyDescriptor.getValue (component);

Public override bool isreadonly {get {return this.basepropertydescriptor.isreadonly;}}

Public override string name {get {return this.basepropertydescriptor.name;}} public override type}} public override type;}} ..basepropertyDescriptor.propertytype;}}

Public Override Void ResetValue (Object Component) {this.basepropertyDescriptor.resetValue (component);}

Public Override Bool ShouldSerialIzeValue (Object Component) {Return this.basepropertyDescriptor.ShousePropertyDescriptor.ShousePropertyValue (component);

Public override void setValue (Object Component, Object Value) {this.basepropertyDescriptor.setValue (Component, Value);}} #ENDREGION

#Region Custom Attribute Use to display the Chinese characters of the left side [Attributeusage (AttributeTargets.property] public class showchinese: system.attribute {prince schinesechar = "";

Public showchinese (string schinesechar) {this.schinesechar = sCHINESECHAR;

Public string chinesechar {get {return this.schinesechar;}}

Public override string toString () {return this.schinesechar;}} #ENDREGON

Usage is as follows:

Public Class Testa: BaseObject

{

[CategoryAttribute ("Global Settings"), ReadonlyAttribute (False), DescriptionAttribute ("Process Show Chinese Name."), ShowCHINESE ("Process Name:") // Use this here. Haha. ] Public string flowname {get {return strflowname;} set {strflowname = value;}}

}

Click quickly, try. If you have any questions, please refer to you.

转载请注明原文地址:https://www.9cbs.com/read-46421.html

New Post(0)