TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
CHAITANYA KIRAN KASANI
NA
335
133.2k
Had A Bug In Captilizing The First Word In A String
Dec 6 2012 4:40 AM
The Below Is My Code For Capitalizing The First Letter In Each Word Of A String Insert/Typed In The TextBox ..The Code Is Well And Good...
But When I Tried To Type A Letter/Word In The Between The String,Then The Cursor Is Jumping To The End Of The String..I Had Tried A Lot..Pls Can Any One Help Me In This...
This Code Is In C#,Winforms:
private void txtCName_KeyPress(object sender, KeyPressEventArgs e)
{
try
{
bool hasSingleWhitespace = txtCName.Text == " ";
if (!(Char.IsLetter(e.KeyChar) || Char.IsControl(e.KeyChar) || Char.IsWhiteSpace(e.KeyChar)))
e.Handled = true;
char[] c = txtCName.Text.ToCharArray();
int j;
for (j = 0; j < txtCName.Text.Length; j++)
{
if (j == 0) c[j] = c[j].ToString().ToUpper()[0];
else c[j] = c[j].ToString().ToLower()[0];
}
txtCName.Text = new string(c);
txtCName.Select(txtCName.Text.Length, 1);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Reply
Answers (
2
)
How to show/hide installed fonts in Windows OS in Win Forms
What is the difference between break and continue statement?