1>PropertyGid 控件输入时显示隐藏密码为(*)
单独写一个PasswordStringConverter 类;
using System.ComponentModel;
using System.Globalization;
namespace Test
{
public class PasswordStringConverter : StringConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return base.CanConvertFrom(context, sourceType);
}
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
if (destinationType.GetType() == typeof(string))
return true;
return base.CanConvertTo(context, destinationType);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (value.GetType() == typeof(string))
{
int stringSize;
string retVal = "* ";
Random randomString = new Random();
if (value != null)
stringSize = ((string)value).Length;
else
stringSize = randomString.Next(10);
for (int i = 0; i < stringSize; i++)
retVal += "* ";
return retVal;
}
return base.ConvertTo(context, culture, value, destinationType);
}
public override bool GetPropertiesSupported(ITypeDescriptorContext context)
{
return false;
}
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
string[] standardValues = new string[1];
int stringSize;
string retVal = "* ";
Random randomString = new Random();
stringSize = randomString.Next(