字母表中的所有字母。
是否可以自动将首字母大写?
我一直在将此代码用于其他程序,但它只允许您输入字母。我正在努力适应它。
Private Sub LettersOnly(ByRef Character As Char)
' Purpose: Validate character input: letters and control keys only
If Char.IsLetter(Character) = False And Char.IsControl(Character) = False Then
MessageBox.Show("Letters only.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
' Stop invalid character appearing in field
Character = Nothing
End If
End Sub
答案 0 :(得分:1)
假设Windows窗体,请尝试:
Private Sub TextBox1_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If (Not Char.IsLetter(e.KeyChar) AndAlso e.KeyChar <> " "c) Then e.Handled = True
If (DirectCast(sender, TextBox).Text.Length = 0) Then e.KeyChar = Char.ToUpper(e.KeyChar)
End Sub
答案 1 :(得分:0)
请注意,如果您指的是Win或Web OFmrs。