Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

force typing in all caps?

Status
Not open for further replies.

bartmc

Programmer
Aug 9, 2005
9
US
Does anyone know how to intercept ALL keystrokes and force all input to be in UPPERCASE? We only accept uppers in our database.

Bart
 
Capture the Keypress event and after each keypress, do txtYourText.Text = txtYourText.Text.ToUpper();
 
Thats exactly what I dont want to do, is have to do that for EVERY thing they type in, thats going to be tons of redundant code, there are probably 40 textboxes on 1 screen.
I want when they press "i" it shows up as "I" not after the fact. I guess i could derive something from text box that implements this but the problem with that code is that it sets
the cursor back to the beginning of the text so if your typing
fast it will come out TSAF. Know how to set the cursor to the end of whats been typed?

Bart
 
You could capture the KeyDown event. If the ASCII code of the key is within the range of lowercase letters, add or subtract the difference to the uppercase letters.

I would recommend creating a new control that extends textbox. Create this functionality. Then do a replace in your code to change TextBox() to YourTextBox()
 
Yeah i think i am going to create a new control.
The problem is the behavior of
this.TB.Text=this.TB.Text.ToUpper()
is a key press event is not trivial.
I cant understand why it reverses the text when its a lower case letter but not when its a upper case one.

So if i type in iMcG iget GMCI, i dont follow the logic, i would think that it would reverse the text(well its not really reversing it it's setting the cursor to the beginning of the text field AFTER it converts the lower case to upper, but does
not appear to be doing it when the origial letter was already uppercase. I'd still think that it would at least do a replace With the exact same text and reset the cursor but it does not appear to be doing so) and i cant figure out how to advance the cursor after a key press.
 
when you do .ToUpper(), it resets the cursor. If you capture the keydown event, you can change the value of the key before it even reaches the textbox. This way, you don't have to worry about the string reversing.
 
Simply change the property "CharacterCasing" of the textboxes from Normal to Upper.

Hope this helps
 
CharacterCasing Requires.

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Im using .NET mobile Framework, so that doesnt work.
 
Response to JurkMonkey, How? I've tried e.Key(Whatever) and they are all read only. How would i get access to it?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top