【问题标题】:Converting password to star * [duplicate]将密码转换为星号 * [重复]
【发布时间】:2014-07-19 17:53:43
【问题描述】:

我现在只是在 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");
        }

【问题讨论】:

    标签: c#


    【解决方案1】:

    您可能正在寻找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;
     }
    

    【讨论】:

      猜你喜欢
      • 2016-06-18
      • 2016-12-19
      • 2018-10-05
      • 2012-06-15
      • 1970-01-01
      • 1970-01-01
      • 2012-12-12
      • 2019-10-03
      • 1970-01-01
      相关资源
      最近更新 更多