将密码转换为星号*

时间:2014-07-19 17:53:44

标签: c#

我现在只是在Visual Studio C#中乱搞,只是想知道如何将插入文本框的密码转换成星星。这是代码和任何帮助。

private void button1_Click(object sender, EventArgs e)
    {
        string Email = TxtEmail.Text;
        string Password = TxtPassword.Text;

        if (Email == "test@gmail.com" && Password == "LOL")
        {
            MessageBox.Show("Login Complete");
        }
        else if (Email == "hotmail@lol.co.uk" && Password == "Lol")
        {
            MessageBox.Show("Login Complete");
        }
        else if (Email == "eg@eg.co.uk" && Password == "eg")
        {
            MessageBox.Show("Login Complete");
        }
        else if (Email == "" && Password == "")
        {
            MessageBox.Show("Login Failed");
        }
        else
        {
            MessageBox.Show("Login Failed", "Login Failed");
        }

1 个答案:

答案 0 :(得分:2)

您可能正在寻找TextBox.PasswordChar Property

  

获取或设置用于屏蔽密码字符的字符   单行TextBox控件。

来自MSDN的示例:

public void CreateMyPasswordTextBox()
 {
    // Create an instance of the TextBox control.
    TextBox textBox1 = new TextBox();
    // Set the maximum length of text in the control to eight.
    textBox1.MaxLength = 8;
    // Assign the asterisk to be the password character.
    textBox1.PasswordChar = '*';
    // Change all text entered to be lowercase.
    textBox1.CharacterCasing = CharacterCasing.Lower;
    // Align the text in the center of the TextBox control.
    textBox1.TextAlign = HorizontalAlignment.Center;
 }