How to use PasswordBox as TextBox? [closed]

百般思念 提交于 2019-12-29 08:26:07

问题


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

Is there a property to do this? Thanks.


回答1:


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.




回答2:


Your best solution would be to have a Password Box with a checkbox underneath that says "Show characters" and then create a Trigger on the Password Box that overlays a TextBox on it for typing and retrieve the text as appropriate.




回答3:


Superimpose a TextBox and a PasswordBox, keeping only one Visible at a time. When you want to switch over, copy over the value of the active one to the other one, and switch their visibilities. Simple.




回答4:


I think everybody agrees on this very basic solution: Use a TextBox if you want to display what the user is typing.



来源:https://stackoverflow.com/questions/12517969/how-to-use-passwordbox-as-textbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!