|
|
Title | Make a TextBox automatically capitalize input using the API |
Keywords | uppercase, upper case, capitalize, TextBox, input |
Categories | Controls, API |
|
|
Use the SetWindowLong API function to make the TextBox automatically convert text into upper case.
|
|
' Make the TextBox convert input to UPPERCASE.
Private Sub SetAllCaps(ByVal txt As TextBox)
Const GWL_STYLE = (-16)
Const ES_UPPERCASE = &H8&
Dim style As Long
style = GetWindowLong(txt.hwnd, GWL_STYLE)
style = style Or ES_UPPERCASE
SetWindowLong txt.hwnd, GWL_STYLE, style
End Sub
|
|
This method has a couple of advantages. First, it is handled at a lower level than the VB event handler so it is more efficient. That's not a huge deal since usually it's a user entering text so it's going to be fast enough either way.
Second, it's "set and forget." Once you set the flag, you don't need to have the VB code cluttering things up. You don't need to write separate event handlers for each TextBox.
|
|
|
|
|
|