Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WinForm
I want to capitalize every first letter in a textBox text and I want when the user start entering the text it will automatically capitalize first letter...
I tried this -:
private void textBox1_TextChanged(object sender, EventArgs e)
        {
            CultureInfo cultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture;
            TextInfo textInfo = cultureInfo.TextInfo;
            textBox1.Text= textInfo.ToTitleCase(textBox1.Text);
        }
but when the first letter capitalized it set the cursor position at the beginning of the text so the text is reversed..
If I want to enter "jayanta" it shows "Atnayaj" But correct is "Jayanta"..
 
I want it like, when we set CharacterCasing property to UPPER then it change the text lower to upper case without changing the cursor position in the textBox...
 
How to fix it??
thanks in advance....
Posted 8-Mar-13 7:27am
Edited 8-Mar-13 8:17am
v2

1 solution

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

Solution 3

use this code into textChanged ! hope help you !
char[] v=textBox1.Text.ToCharArray();
string s = v[0].ToString().ToUpper();
for (int b = 1; b < v.Length; b++)
     s += v[b].ToString().ToLower();
textBox1.Text = s;
textBox1.Select(textBox1.Text.Length,0);
            
  Permalink  
v2
Comments
Jayanta Chatterjee at 8-Mar-13 13:13pm
   
Sir, Same result, Its set cursor position at the beginning of the text..
I want it like, when we set CharacterCasing property to UPPER then it change the text lower to upper case without changing the cursor position in textBox...
Member 848045 at 19-Dec-13 19:41pm
   
Thank you for the solution it helped me
source.compiler at 8-Mar-13 13:20pm
   
see solution again, i improved it! (last line)
Jayanta Chatterjee at 8-Mar-13 13:24pm
   
Thanks a Lottttttttttt Sir....
It works..
source.compiler at 8-Mar-13 13:26pm
   
actually your answer is last line!
Jayanta Chatterjee at 8-Mar-13 13:28pm
   
Yes, I know ...
I added it in my code -:
CultureInfo cultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture;
TextInfo textInfo = cultureInfo.TextInfo;
textBox1.Text= textInfo.ToTitleCase(textBox1.Text.ToLower());
textBox1.Select(textBox1.Text.Length, 0);
 
Thanks again... :-)

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

  Print Answers RSS
0 OriginalGriff 280
1 Maciej Los 280
2 BillWoodruff 240
3 Afzaal Ahmad Zeeshan 239
4 Sergey Alexandrovich Kryukov 195
0 OriginalGriff 6,499
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,193
3 Manas Bhardwaj 4,657
4 Maciej Los 4,120


Advertise | Privacy | Mobile
Web01 | 2.8.1411019.1 | Last Updated 8 Mar 2013
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