Is it possible to mark a property shown in a property grid as a password field

Chris B picture Chris B · Jan 14, 2009 · Viewed 7.6k times · Source

I'm using C# and have a windows form containing a property grid control.

I have assigned the SelectedObject of the propertygrid to a settings file, which displays and lets me edit the settings. However one of the settings is a password - and I'd like it to display asterisks in the field rather than the plain text value of the password setting.

The field will be encrypted when saved, but I want it to behave like a normal password entry box with asterisks displayed when the user is entering in the password.

I'm wondering if there is an attribute that can be applied to the setting property to mark it as being a password?

Thanks.

Answer

Nicolas Cadilhac picture Nicolas Cadilhac · Jan 14, 2009

Starting with .Net 2, you can use the PasswordPropertyTextAttribute attached to your password property.

Hope this helps.