I have been doing a project recently. Need to be a thing similar to a vs2003 interface designer. That is to show a panel, you can drag and drop the specified control above. Then there is a PropertyGrid to display the properties of the control.
The current problem is that the code has been finished, the test person suddenly puts forward, the property name in the propertyGrid is preferably Chinese. Moreover, the value of some enumeration properties should also display Chinese enumeration items when setting.
After some search, I found the code of Globalized Property Grid written by Gerd KleveSaat on the Internet to solve the first problem. Just here I use a two-dimensional table, do the conversion of the Chinese attribute name:
Private static string [,] table = new string [,]
{
{"Location", "position"}
}
The second requirement is not so good. I used to find an article in MSDN, and there is a method of selecting the attribute value in the PropertyGrid. However, well known, the attribute of the Enum type cannot be Chinese. If you replace String, you can do solve it. But this property is frequent in the program core code, so you need to modify the entire program core from the head to the end. It is not guaranteed that you can't have problems.
I want to think, or I decided to play a skill: hide the original attribute. Newly do the properties of a String type, using this property to implement Chinese in the propertyGrid (actually INTERNATIONALIZED!). There are not movable in other parts of the program. It's just that this method is that I think of a property in the big flag.
code show as below:
[Description ("Test Properties", Category ("Test")]
[Editor (Testeditor), TypeOf (UITYPEEDITOR)]]
Public String STEST
{
get
{
Return Testenumname.Table [TestenumName.indexof (Test.toString ()), 1];
}
set
{
Test = (TESTENUM) ENUM.PARS (Testenum), TestenumName.table [Testenumname.indexof (Value), 0]);
}
}
Public Enum Testenum
{
Fsnull,
FSNN
}
Public Class Testenumname
{
Public static string [,] table = new string [,]
{
{"fsnull", "no format"}, // 0
{"fsnn", "lowercase number"}, // 1
}
Public Static int indexof (String S)
{
int RET = -1;
IF (s! = null)
{
For (int i = 0; i <= table.getupperbound (0); i )
{
IF ((Table [i, 1] .trim (). TOLOWER () == S.trim (). TOLOWER ()) || (Table [i, 0] .trim (). TOLOWER () == s. Trim (). TOLOWER ()))))
{
Ret = i;
Break;
}
}
}
Return Ret;
}
}
Since I have always lazy, like Copy & Paste, I deliberately write the above code into common. There is an instructions and comparison tables that need to be modified, and of course, there are also types and properties names.
Reference: http://www.codeproject.com/cs/misctrl/globalizedpropertyGrid.asp
Http://www.microsoft.com/china/msdn/archives/library/dndotNet/html/usingpropGrid.asp