Click here to Skip to main content
11,704,315 members (44,925 online)
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 6:27am
Edited 8-Mar-13 7: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 Sergey Alexandrovich Kryukov 740
1 OriginalGriff 520
2 Maciej Los 355
3 Andy Lanng 284
4 CPallini 275
0 OriginalGriff 8,824
1 Sergey Alexandrovich Kryukov 8,247
2 CPallini 5,197
3 Maciej Los 4,726
4 Mika Wendelius 3,606


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