Click here to Skip to main content
11,644,731 members (66,910 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C#2.0
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
Edited 30-Oct-12 1:26am
ProgramFOX at 30-Oct-12 7:20am
What do you mean with 'change the text into uppercase in reverse order'?
Imteyaz Ahmed at 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

Laugh | :laugh:
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 at 30-Oct-12 7:26am
Thanks a lot. its working.
OriginalGriff at 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
0 OriginalGriff 680
1 494
2 Sergey Alexandrovich Kryukov 464
3 Afzaal Ahmad Zeeshan 404
4 CPallini 386
0 OriginalGriff 1,020
1 Sergey Alexandrovich Kryukov 673
2 DamithSL 656
3 Afzaal Ahmad Zeeshan 652
4 CPallini 555

Advertise | Privacy | Mobile
Web01 | 2.8.150731.1 | Last Updated 30 Oct 2012
Copyright © CodeProject, 1999-2015
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