How can I make everything in a textbox lowercase.
Printable View
How can I make everything in a textbox lowercase.
VB Code:
Text1.Text = LCase(Text1.Text)
You can do that "as you type" and/or on LostFocus evnt:
VB Code:
Private Sub Text1_KeyPress(KeyAscii As Integer) KeyAscii = Asc(LCase(Chr(KeyAscii))) End Sub Private Sub Text1_LostFocus() Text1.Text = LCase(Text1.Text) End Sub
Thank you both.
Private Sub textbox_change()
textbox.text = LCase(textbox.text)
End Sub
(Yall beat me to it)
You can also change the style of the TextBox so that it automatically changes all characters to lower case as they are typed. This will also change the characters that are pasted into the control.VB Code:
Private Declare Function SetWindowLong _ Lib "user32.dll" Alias "SetWindowLongA" ( _ ByVal hwnd As Long, _ ByVal nIndex As Long, _ ByVal dwNewLong As Long) As Long Private Declare Function GetWindowLong Lib "user32.dll" _ Alias "GetWindowLongA" ( _ ByVal hwnd As Long, _ ByVal nIndex As Long) As Long Private Const GWL_STYLE As Long = -16 Private Const ES_LOWERCASE As Long = &H10& Private Sub Form_Load() Dim nStyle As Long nStyle = GetWindowLong(Text1.hwnd, GWL_STYLE) Or ES_LOWERCASE Call SetWindowLong(Text1.hwnd, GWL_STYLE, nStyle) End Sub