Search code examples
c#textboxcapitalization

While entering text into the text box I want the first letter of the text to be capitalized automatically


I want to make an event that when entering text into the text box the first letter of the text to be capitalized automatically in fastest way.


Solution

  • Try something simple like this:

    create a text_changed event on the text box

     private void textBox1_TextChanged(object sender, EventArgs e)
        {
          {
            if ((textBox1.Text.Length) == 1)
            {
                textBox1.Text = textBox1.Text[0].ToString().ToUpper();
                textBox1.Select(2, 1);
    
            }
          }
        }
    

    Should you have issues with the formatting of the text due to other requirements, than it needs to be done in a different way.