我目前正在为我的程序创建一个登录表单,其中我有两个文本框电子邮件和密码的水印。
当文本框为空时,其水印文本将显示在其中,如“用户名”和“密码”。 我的代码是: 公共类frmLogin
Private Sub TextBox2_LostFocus(sender As Object, e As System.EventArgs)
If TextBox2.Text = "" Then
TextBox2.ForeColor = Color.DarkGray
TextBox2.Text = "Username"
End If
End Sub
Private Sub TextBox2_GotFocus(sender As Object, e As System.EventArgs) Handles TextBox2.GotFocus
TextBox2.Text = ""
TextBox2.ForeColor = Color.Black
End Sub
Private Sub TextBox1_GotFocus(sender As Object, e As System.EventArgs) Handles TextBox1.GotFocus
If TextBox2.Text = "" Then
TextBox2.ForeColor = Color.DarkGray
TextBox2.Text = "Username"
End If
TextBox1.Text = ""
TextBox1.ForeColor = Color.Black
End Sub
Private Sub TextBox1_LostFocus(sender As Object, e As System.EventArgs) Handles TextBox1.LostFocus
If TextBox1.Text = "" Then
TextBox1.ForeColor = Color.DarkGray
TextBox1.Text = "Password"
End If
End Sub
结束班
但现在我的问题是我想使用密码字符作为密码。但我仍然希望水印文本是常规文本。当我检查使用密码char时,它将我的水印变为“**”而不是“密码”。我该如何解决这个问题?
答案 0 :(得分:-1)
这似乎很好:
Private Sub TextBox1_GotFocus(sender As Object, e As System.EventArgs) Handles TextBox1.GotFocus
Textbox1.PasswordChar = "*"
Textbox1.Clear()
End Sub
Private Sub TextBox1_LostFocus(sender As Object, e As System.EventArgs) Handles TextBox1.LostFocus
TextBox1.PasswordChar = ControlChars.NullChar
End Sub