【问题标题】:Visual Basics Watermark passwordchar?Visual Basics 水印密码字符?
【发布时间】:2017-01-24 22:44:58
【问题描述】:

我目前正在为我的程序制作一个登录表单,其中我有两个文本框电子邮件和密码的水印。

当文本框为空时,其水印文本会出现在其中,如“用户名”和“密码”。 我的代码是: 公共类 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

结束类

但现在我的问题是我想使用密码字符作为密码。但我仍然希望水印文本是普通文本。当我检查使用密码字符时,它会将我的水印变成“**”而不是“密码”。我该如何解决?

【问题讨论】:

  • 您正在重新创建轮子 - Cue Banner Text 内置在 Windows 中,并且独立于 text 属性工作。否则在 Enter 和 Leave 上设置 PasswordChar

标签: vb.net login watermark


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-09
    • 2011-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多