How to use PasswordBox as TextBox?

Nick picture Nick · Sep 20, 2012 · Viewed 8.5k times · Source

I have a PasswordBox and I need to use this control even as a TextBox. I need to display normal text and not the typical black dots

enter image description here

Is there a property to do this? Thanks.

Answer

Joshua Van Hoesen picture Joshua Van Hoesen · Sep 20, 2012

Here is your answer:

  1. Use a Textbox
  2. When you want the text masked set TextBox.UseSystemPasswordChar = true;
  3. when you want to see the text set TextBox.UseSystemPasswordChar = false;
  4. Profit

Example:

private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
    if (checkBox1.Checked == true)
    {
        TextBox.UseSystemPasswordChar = true;
    }
    else 
    {
        TextBox.UseSystemPasswordChar = false;
    }
}

Black dots when you want them, words when you don't. You can use what ever trigger/logic you want for the turning on and off but this way you are only using one control and get all the functionality that you specified you needed.