hi
i want to do the capital letter of erver word in text box
what i use the function or code
i mean
i write in my text box i.e " dharmesh sharma "
now this string will me make like this "Dharmesh Sharma" in textbox
how do this in textbox
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Nilanka DharmadasaRank #1,875 · 794 reputationPosted Nov 18, 2009, 11:22 PM EST
Add these two lines with other using statements.
using System.Globalization;
using System.Threading;
Then write following code.
private void textBox1_Leave(object sender, EventArgs e)
{
CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture;
TextInfo textInfo = cultureInfo.TextInfo;
textBox1.Text = textInfo.ToTitleCase(textBox1.Text);
}
This will change the text wehn you leave the text box. If this should be changed, then copy this code under the event you want.
If you need help on this, let me know.
If you find this useful, please mark this as accepted.
Gaurish Kumar108 reputationPosted Nov 18, 2009, 11:27 PM EST
Create one function like this
public string TitleCase(string value) { return System.Globalization.CultureInfo.CurrentUICulture.TextInfo.ToTitleCase(value.ToLower()); } This function will return you string whose first letter is capital.Lalit MRank #1,186 · 1.5K reputationPosted Nov 18, 2009, 11:56 PM EST
set the TextBox.CharacterCasing to Upper.
Muhammad Shahid Farooq107 reputationPosted Nov 18, 2009, 11:58 PM EST
Use the following small snippet, this will help you
private void textBox1_Leave(object sender, System.EventArgs e)
{
textBox1.Text = ConvertToPascalCase(textBox1.Text).TrimStart();
}
public static string ConvertToPascalCase(string str)
{
//if nothing is proivided throw a null argument exception
if (str == null) throw new ArgumentNullException("str", "Null text cannot be converted!");
if (str.Length == 0) return str;
//split the provided string into an array of words
string[] words = str.Split(' ');
//loop through each word in the array
for (int i = 0; i < words.Length; i++)
{
//if the current word is greater than 1 character long
if (words[i].Length > 0)
{
//grab the current word
string word = words[i];
//convert the first letter in the word to uppercase
char firstLetter = char.ToUpper(word[0]);
//concantenate the uppercase letter to the rest of the word
words[i] = " " + firstLetter + word.Substring(1);
}
}
//return the converted text
return string.Join(string.Empty, words);
}