Show mask for password in PropertyGrid

为了在 PropertyGrid 中将密码显示为*需要使用PasswordPropertyText属性。

  • 配置属性
class Settings { 
    [CategoryAttribute("Login"), DisplayName("User Name"), DescriptionAttribute("Login Name")] 
    public string Username { get; set; }
 
    [CategoryAttribute("Login"), DisplayName("Password"), DescriptionAttribute("Login Password")] 
    [PasswordPropertyText(true)] 
    public string Password { get; set; } 
}
  • 应用配置
private void MainForm_Load(object sender, EventArgs e) { 
    propertyGrid.SelectedObject = new Settings(); 
    propertyGrid.PropertySort = PropertySort.NoSort; 
}