Capital letters in Textbox

K

Kenan

Public Declare Function GetFocus Lib "Coredll" () As
Integer

Public Declare Function GetWindowLong Lib "Coredll"
Alias "GetWindowLongW" (ByVal hwnd As Integer, ByVal
nIndex As Integer) As Integer

Public Declare Function SetWindowLong Lib "Coredll"
Alias "SetWindowLongW" (ByVal hwnd As Integer, ByVal
nIndex As Integer, ByVal dwNewLong As Integer) As Integer

Const GWL_STYLE = -16
Const ES_NUMBER = 8192
Const ES_UPPERCASE = 8
Const ES_LOWERCASE = 16

Public Function EnsureNumeric(ByVal pTextBox As
TextBox, ByVal Force As Boolean)
Dim hWnd As Integer
Dim Style As Integer
Try
pTextBox.Focus()
hWnd = GetFocus

Style = GetWindowLong(hWnd, GWL_STYLE)
If Force Then
Style = Style Or ES_NUMBER
Else
Style = Style And Not ES_NUMBER
End If
SetWindowLong(hWnd, GWL_STYLE, Style)
Catch
End Try
End Function

Public Function EnsureUpperCase(ByVal pTextBox As
TextBox)
Dim hWnd As Integer
Dim Style As Integer

pTextBox.Focus()
hWnd = GetFocus

Style = GetWindowLong(hWnd, GWL_STYLE)
Style = Style Or ES_UPPERCASE
SetWindowLong(hWnd, GWL_STYLE, Style)
End Function
 
N

Neil Cowburn [MVP]

There's a MUCH simpler way....

In the TextChanged event of the textbox, do something like this:

// Convert Text to upper case
textBox1.Text = textBox1.Text.ToUpper();
// Move cursor to end of Text
textBox1.SelectionStart = textBox1.Text.Length;

HTH
Neil

--
Neil Cowburn
Microsoft Windows Embedded MVP
Content Master Ltd

www.contentmaster.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top