how to validate the Textbox allows only first character Capital latter in c#.net?

1.7k Views Asked by At

I have a task, my textbox accepts only first character capital lettr and remaing characters normal.

1

There are 1 best solutions below

1
suco2007 On BEST ANSWER

Use KeyPress event of textbox:


    private void txt_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (txt.Text != "" && !Char.IsUpper(txt.Text, 0))
        {
            txt.Text = Char.ToUpper(txt.Text[0]) + txt.Text.Substring(1);
        }
    }