查了一下网络,有方案是在GET{}中只返回*****字符串,不返回实际密码;但如此处理的话,界面显示是能解决了,问题是内部程序处理的时候,要访问读取这个属性又比较罗嗦了,请问有什么好的解决方案吗?

解决方案 »

  1.   

    这个我是说在propertygrid中显示密码
      

  2.   

    propertygrid没用过
    可不可以在显示的地方添加TextBox什么的
    直接改变TextBox属性变为“****”就好了
      

  3.   

    还是希望能在propertygrid中解决,实在没办法也只能将就采用变通方法了
      

  4.   

    public class PasswordStringConverter: StringConverter//System.ComponentModel.TypeConverter
    {
    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( 10 ); for( int i = 0; i < stringSize; i++ )
    retVal += "*"; standardValues[0] = retVal; return new StandardValuesCollection( standardValues );
    }
    } /// <summary>
    /// Summary description for MyTextbox.
    /// </summary>
    public class MyTextbox : System.Windows.Forms.TextBox
    {
    [TypeConverter(typeof(PasswordStringConverter))]
    public new string Text
    {
    get
    {
    return base.Text;
    }
    set
    {
    base.Text = value;
    }
    }
    }
      

  5.   

    PasswordStringConverter class is from:
    http://www.codeproject.com/cs/miscctrl/PropertyGridDataFormattin.asp