Visual Basics 水印密码字符?
Visual Basics Watermark passwordchar?
我目前正在为我的程序创建一个登录表单,其中我有两个文本框电子邮件和密码的水印。
当文本框为空时,它的水印文本会像"Username"和"Password"一样出现在其中。
我的代码是:
Public Class 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
结束Class
但现在我的问题是我想使用密码字符作为密码。但我仍然希望水印文本为常规文本。当我检查使用密码字符时,它会将我的水印变成“**”而不是 "Password"。我该如何解决?
这看起来不错:
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
我目前正在为我的程序创建一个登录表单,其中我有两个文本框电子邮件和密码的水印。
当文本框为空时,它的水印文本会像"Username"和"Password"一样出现在其中。 我的代码是: Public Class 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
结束Class
但现在我的问题是我想使用密码字符作为密码。但我仍然希望水印文本为常规文本。当我检查使用密码字符时,它会将我的水印变成“**”而不是 "Password"。我该如何解决?
这看起来不错:
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