Convert first letter in a string to capital

I have a Text Box, (say txtBox1) which I am asking the user to enter some text in.
I need to check if the first letter in the box's text is uppercase.
If not uppercase convert ONLY the first letter to uppercase and keep the remaining letters as lowercase.

Thank you
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

There might be more efficient ways to do this, but this will give you the result your looking for.  In the Leave event for your text box drop in this line of code.

        private void textBox1_Leave(object sender, EventArgs e)
            textBox1.Text = textBox1.Text[0].ToString().ToUpper() + textBox1.Text.Substring(1);

Open in new window

adamtraskAuthor Commented:
Thank you. This partly works as it changes the first letter to uppercase, but if the user enters an uppercase letter in the middle of the word like "adAm"? It would become AdAm!

Is there a way to convert the rest of the text to lowercase?

Yeah, not a problem, you just need to add a .ToLower() to the second part like below.

textBox1.Text = textBox1.Text[0].ToString().ToUpper() + textBox1.Text.Substring(1).ToLower();

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
adamtraskAuthor Commented:
Thank you so much.
No problem, glad I could help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.