Force Uppercase

I have a textbox into which data is keyed.
I want to be able to have the keys entered set to upper case before they appear in the textbox.

I dont want the user to have to use the shift key. how can i do this

Can i do something inside the KeyDown or KeyPressed event that will convert them to uppercase



Answer this question

Force Uppercase

  • robbykfet

    Add this code to the KeyPress event:


    if (char.IsLower(e.KeyChar))
    {
        e.KeyChar =
    char
    .ToUpper(e.KeyChar);
    }

     


  • amodir

    or you could just make whatever the user types in, to uppercase after they press a continue button or something.

    Dim theString as string = Me.theTextBox.Text.ToUpper()



  • Tramel

    Not a good solution...

    You're converting all the text to upper case. This makes caracter insertion impossible. The cursor won't move....

    Keychar shound't be read-only!!!!


  • ashvik

    e.KeyChar is readonly as passed from the base control. The following works in VB.NET:

    If Char.IsLower(e.KeyChar) Then

    e.Handled = True

    SendKeys.Send(Char.ToUpper(e.KeyChar))

    End If


  • sicikim

    Found a solution

    Add the following code into the textbox's keyup event


    txtBTAddr1.Text = txtBTAddr1.Text.ToUpper
    txtBTAddr1.Select(txtBTAddr1.Text.Length, 0)

     



  • Mohammad najdawi

    I've tried it on a regular WinForms app, in VS2005.

    I don't know, it might be a CF or a version problem... Sad

  • Ramji

    I have tried this, however it says the KeyChar is ReadOnly



    Private Sub txtBTAddr1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtBTAddr1.KeyPress
            If Char.IsLower(e.KeyChar) Then
                e.KeyChar = Char.ToUpper(e.KeyChar)
            End If
        End Sub

     


  • Bill at Rockford

    hello Barry,

    Maybe you could use the OpenNETCF.Windows.Forms.TextBox2 control.
    It has a property that configures the character casing that should be used:

    textBox.CharacterCasing = CharacterCasing.Upper;

    Greetings,

    Peter Vrenken





  • zxber

    Add the below code in a css file and add it to your project. Apply this css to the control say a textbox like :
    <asp:TextBox ID="txtSurname" CssClass="TextBoxUpperCase" runat="server" ><asp:TextBox>

  • Force Uppercase