none
capital letters in text box

    General discussion

  •  hai

    i have a c# form contains textbox1

    how i get all my letters in capital letters when i type?(regardless of capslock on or off)

    also if i need begenning letter only in caps how i can get

    regards

    Monday, December 01, 2008 2:13 PM

All replies

  •  
    public string ToUpper()  
        Member of System.String  
     
    Summary:  
    Returns a copy of this System.String converted to uppercase, using the casing rules of the current culture.  
     
    Return Values:  
    A System.String in uppercase.  
     
     
     void textBox1_TextChanged(object sender, EventArgs e)  
            {  
                this.textBox1.Text = this.textBox1Text.ToUpper();  
            } 

    Rudedog   =8^D
    Mark the best replies as answers. "Fooling computers since 1971."
    Monday, December 01, 2008 2:26 PM
  • I think RudeDog's method might change the order of text typed, right to left and also change insertion point



    I suggest CharacterCasing property, its in designtime, just look at the property of textbox

    or in code, put in form's load event or somewhere during intialization

    textBox1.CharacterCasing = CharacterCasing.Upper

    Arjun Paudel Not Getting Live Alerts at the moment
    Monday, December 01, 2008 3:15 PM
  • you can use the toUpper method and then move the cursor using the select method


    textBox1textBox1.Text = textBox1.Text.ToUpper(); 
    textBox1.Select(textBox1.Text.Length, 1); 

    Monday, December 01, 2008 3:23 PM
  • if you only want the first character you can say if length is 1.

    if (textBox1.Text.Length == 1) 
       textBox1textBox1.Text = textBox1.Text.ToUpper(); 
       textBox1.Select(textBox1.Text.Length, 1); 

    Monday, December 01, 2008 3:25 PM
  • but my point is not only that, insertion point can be anywhere, cant assume its in the last and yes it can be remembered and put again but does not this look simple and easy?

    textBox1.CharacterCasing = CharacterCasing.Upper

    Arjun Paudel Not Getting Live Alerts at the moment
    Monday, December 01, 2008 3:29 PM
  • Arjun's suggestion is the way to go, IMO.
    Monday, December 01, 2008 3:38 PM
  • Arjun Paudel said:

    I think RudeDog's method might change the order of text typed, right to left and also change insertion point



    I suggest CharacterCasing property, its in designtime, just look at the property of textbox

    or in code, put in form's load event or somewhere during intialization

    textBox1.CharacterCasing = CharacterCasing.Upper


    Arjun Paudel Not Getting Live Alerts at the moment



    Arjun, is right to a degree.  Good Call.

    I just tested it out  Writing data to the TextBox moves the cursor to the beginning of the line of text, instead of leaving it at the end as one would expect, well in my culture at least :)  The end result is that text is typed out backwords!

    Rudedog  =8^D
    Mark the best replies as answers. "Fooling computers since 1971."
    Monday, December 01, 2008 4:07 PM
  • Arjun Paudel said:

    but my point is not only that, insertion point can be anywhere, cant assume its in the last and yes it can be remembered and put again but does not this look simple and easy?

    textBox1.CharacterCasing = CharacterCasing.Upper


    Arjun Paudel Not Getting Live Alerts at the moment



    Can this technique be used to uppercase only the first character as per the original post??
    Monday, December 01, 2008 5:28 PM
  • thank for all

    my code is working
    Monday, December 01, 2008 7:12 PM