I don't know of a way to capitalize the input as the user types.
The CharacterCasing property is used to perform case conversions, but it allows upper case or lower case (or normal) for the complete text.
One workaround could be to write a function to capitalize the text before you process it in your application, or when some event occur in the text box (TextChanged, or Validated for example).
The capitalize function could look like this:
<pre>public static string Capitalize(string input)
{
if(string.IsNullOrEmpty(input)) return string.Empty;
return input.Substring(0, 1).ToUpper() + input.Substring(1).ToLower();
}</pre>
-----------------------------------------------------------
This piece of code <a href="http://dqsd.svn.sourceforge.net/viewvc/dqsd/trunk/dqsd/searches/ccase.xml">here</a> might be a good place to start as far a word capping function.
Good Luck!
-Flame
Last Wiki Answer Submitted: November 20, 2008 3:37 pm by carlosdl63,535 pts.
All Answer Wiki Contributors: carlosdl63,535 pts. ,
Flame14,895 pts.
If you live outside the United States, by submitting your email address you consent to having your personal data transferred to and processed in the United States.
thanks but your answer does not resoleve my question. Delphi function does it perfectly for starting words in a sentence, and the user just keep typing without having to resort to Shift key combination. The user should see the capitalised starting letter as they continue to type
Let us expand my earlier ideas, so that the first letter will always be capitalised and the rest be forced to lowercase.
Method 1 – use VB.NET which offers
MyNewString = StrConv(MyString, vbProperCase)
Method 2 – convert to character array to freely manipulate each letter. This has the advantage of over-riding the caps lock but only capitalises the first letter of the first word.
Method 3 – use a TextInfo object which has a ToTitleCase method. This has thye advantage of capitalising thye first letter of each separate word but is over-ridden by caps lock. (This method requires using System.Globalization and System.Threading.
Here is the code for methods 2 and 3
private void textBox1_TextChanged(object sender, EventArgs e)
{
char[] c = textBox1.Text.ToCharArray();
int j;
for (j = 0;j<textBox1.Text.Length;j++) {
if (j==0) c[j]=c[j].ToString().ToUpper()[0];
else c[j] = c[j].ToString().ToLower()[0];
}
textBox1.Text = new string(c);
textBox1.Select(textBox1.Text.Length,1);
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
CultureInfo cI = Thread.CurrentThread.CurrentCulture;
TextInfo textInfo = cI.TextInfo;
textBox2.Text = textInfo.ToTitleCase(textBox2.Text);
textBox2.Select(textBox2.Text.Length, 1);
}
thanks but your answer does not resoleve my question. Delphi function does it perfectly for starting words in a sentence, and the user just keep typing without having to resort to Shift key combination. The user should see the capitalised starting letter as they continue to type
Here is one w
private void textBox1_TextChanged(object sender, EventArgs e) { if ((textBox1.Text.Length) == 1) { textBox1.Text = textBox1.Text[0].ToString().ToUpper(); textBox1.Select(2, 1); } }Let us expand my earlier ideas, so that the first letter will always be capitalised and the rest be forced to lowercase.
Method 1 – use VB.NET which offers
Method 2 – convert to character array to freely manipulate each letter. This has the advantage of over-riding the caps lock but only capitalises the first letter of the first word.
Method 3 – use a TextInfo object which has a ToTitleCase method. This has thye advantage of capitalising thye first letter of each separate word but is over-ridden by caps lock. (This method requires using System.Globalization and System.Threading.
Here is the code for methods 2 and 3
private void textBox1_TextChanged(object sender, EventArgs e) { char[] c = textBox1.Text.ToCharArray(); int j; for (j = 0;j<textBox1.Text.Length;j++) { if (j==0) c[j]=c[j].ToString().ToUpper()[0]; else c[j] = c[j].ToString().ToLower()[0]; } textBox1.Text = new string(c); textBox1.Select(textBox1.Text.Length,1); } private void textBox2_TextChanged(object sender, EventArgs e) { CultureInfo cI = Thread.CurrentThread.CurrentCulture; TextInfo textInfo = cI.TextInfo; textBox2.Text = textInfo.ToTitleCase(textBox2.Text); textBox2.Select(textBox2.Text.Length, 1); }it tried method2 and it works..thanks a lot
twlp123
if (string.Compare(input.Substring(i,1),input.Substring(i,1).ToUpper()) == 0)
whats the meaning of this code