Thursday, May 27, 2010

Password Property in a PropertyGrid

If you have a property in a class to keep track of a password, and you want that class to be editable in a PropertyGrid, but you don't want the password to be human readable, then you just need to add the attribute PasswordPropertyTextAttribute to your property and set the in argument to true, like the example below. This way the users will see circles instead of the pressed keys.
  
[PasswordPropertyTextAttribute(true)]
public string Password { get; set; }