VB.net密码框输入一个字母停顿一下就变*号
像QQ登录窗口那样的密码框,怎样设置,输入一个字母或者数字,停顿一两秒之后就自动变成*,求方法求解析求帮助
[解决办法]
简单的写了一个,你试试
Public Class TextBoxPassword
Inherits TextBox
Private _value As String = String.Empty
Public Property Value As String '密码框真正内容
Get
Return _value
End Get
Set(value As String)
_value = value
End Set
End Property
Private m_currChar As Char
Protected Overrides Sub OnKeyPress(e As KeyPressEventArgs)
If (e.KeyChar >= "A"c And e.KeyChar <= "Z"c) Or
(e.KeyChar >= "a"c And e.KeyChar <= "z"c) Or
(e.KeyChar >= "0"c And e.KeyChar <= "9"c) Then '只能输入字母和数字,如果可以输特殊字符,在此加判断条件
m_currChar = e.KeyChar
Dim t As New System.Threading.Thread(New System.Threading.ThreadStart(AddressOf ChangeStart))
t.Start()
End If
MyBase.OnKeyPress(e)
End Sub
Private Delegate Sub ChangeStartHandler()
Private Sub ChangeStart()
Dim c As New ChangeStartHandler(AddressOf ChangeStartFunc)
Me.BeginInvoke(c)
End Sub
Private Sub ChangeStartFunc()
Thread.Sleep(500)
Dim temp = _value
If (temp Is Nothing) Then
temp = ""
End If
Dim i As Integer = Me.SelectionStart
temp = temp.Substring(0, i - 1) + m_currChar
Dim str = Me.Text.Substring(0, i - 1) + "*"
If (i < Me.Text.Length) Then
str = str & Me.Text.Substring(i)
temp = temp & _value.Substring(i - 1)
End If
_value = temp
Me.Text = str
Me.SelectionStart = i
Me.SelectionLength = 0
End Sub
End Class