Click here to Skip to main content
Rate this: bad
good
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)
      {
          textBox1.Text=textBox1.Text.ToUpper();
      }
Posted 30-Oct-12 2:17am
Edited 30-Oct-12 2:26am
v2
Comments
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
good
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...
  Permalink  
Comments
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 Sergey Alexandrovich Kryukov 575
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,476
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,917


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 30 Oct 2012
Copyright © CodeProject, 1999-2014
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