Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
C#
private void textBox1_KeyUp(object sender, KeyEventArgs e)
      {
          textBox1.Text=textBox1.Text.ToUpper();
      }
Posted
Updated 30-Oct-12 1:26am
v2
Comments
Thomas Daniels 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

: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:
C#
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...
 
Share this answer
 
Comments
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900