VB.net限制只能輸入多少字並大寫,以下是練習。
'TextBox limit character digits user input
Public Sub limitTextBoxDigits(ByRef obj As System.Windows.Forms.TextBox, ByVal digits As Integer)
obj.CharacterCasing = Windows.Forms.CharacterCasing.Upper
If obj.SelectedText <> "" Then
Dim selIdx As Integer = obj.SelectionStart
obj.Text = obj.Text.Remove(obj.SelectionStart, obj.SelectionLength)
obj.Select(selIdx, 1)
End If
If obj.Text.Length >= digits Then obj.Text = obj.Text.Remove(digits - 1, 1) : obj.Select(digits - 1, 1)
End Sub
沒有留言:
張貼留言