2014-07-19 97 views
-1

我只是在Visual Studio C#中搞亂,只是想知道如何將插入到文本框中的密碼轉換爲星星。這裏的代碼和任何幫助表示讚賞。將密碼轉換爲星*

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

     if (Email == "[email protected]" && Password == "LOL") 
     { 
      MessageBox.Show("Login Complete"); 
     } 
     else if (Email == "[email protected]" && Password == "Lol") 
     { 
      MessageBox.Show("Login Complete"); 
     } 
     else if (Email == "[email protected]" && Password == "eg") 
     { 
      MessageBox.Show("Login Complete"); 
     } 
     else if (Email == "" && Password == "") 
     { 
      MessageBox.Show("Login Failed"); 
     } 
     else 
     { 
      MessageBox.Show("Login Failed", "Login Failed"); 
     } 

回答

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; 
}