Click here to Skip to main content
13,000,636 members (57,037 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I want a textbox which allows the user to accept lower case but after keypressing it changes to upper case. For this I am using this code but it is giving the problem like it changes the text into uppercase but in reverse order. pls help me to do this.
private void textBox1_KeyUp(object sender, KeyEventArgs e)
Posted 30-Oct-12 1:17am
Updated 30-Oct-12 1:26am
ProgramFOX 30-Oct-12 7:20am
What do you mean with 'change the text into uppercase in reverse order'?
Imteyaz Ahmed 30-Oct-12 7:22am
I am writing "imteyaz" but its is accepting like "ZAYTEMI" and the cursor is at the starting position.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

It's not that the data is being entered in reverse, it's that when you set the Text property, the insertion point is moved to the beginning of the control each time. Try this:
int cursor = textBox1.SelectionStart;
textBox1.Text = textBox1.Text.ToUpper();
textBox1.SelectionStart = cursor;
But I would probably have used TextChanged event instead, as it will avoid the odd visual effect you will get, and make sure that pasted data is also in upper case.

If you do use TextChanged, set a flag, because setting the Text property will cause a TextChanged event, which will set the Text property, which...
Imteyaz Ahmed 30-Oct-12 7:26am
Thanks a lot. its working.
OriginalGriff 30-Oct-12 7:32am
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170624.1 | Last Updated 30 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100