我想輸入數字只有並且不允許非數字,請幫助我這個。只允許WPF中的密碼框中的數字
這段代碼在文本框不過,這並不與PasswordBox
Dim textBox As TextBox = TryCast(sender, TextBox)
Dim selectionStart As Int32 = textBox.SelectionStart
Dim selectionLength As Int32 = textBox.SelectionLength
Dim newText As [String] = [String].Empty
Dim count As Integer = 0
For Each c As [Char] In textBox.Text.ToCharArray()
If [Char].IsDigit(c) OrElse [Char].IsControl(c) Then
newText += c
End If
Next
textBox.Text = newText
textBox.SelectionStart = If(selectionStart <= textBox.Text.Length, selectionStart, textBox.Text.Length)
工作謝謝
你爲什麼不把你到目前爲止試過嗎?關閉我的頭頂,我會讓密碼框訂閱keyup和keydown事件,如果最後一個字符是數字選項,您可以在那裏檢查。 –
我把代碼與我一起工作在TextBox – shhada