我只想输入数字,不允许非数字,请帮助我。
此代码在 TextBox 但它不适用于 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)
谢谢你