CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2004
    Location
    In the back seat of New Horizons.
    Posts
    1,238

    Converting characters to upper-case...

    Code:
    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs) _
      Handles TextBox1.KeyPress
      ' replace the selected text with an uppercase character. (Inserts at caret position 
       '  if no text is selected.)
      If TextBox1.Text.Length < TextBox1.MaxLength Then
        TextBox1.SelectedText = e.KeyChar.ToString.ToUpper
      End If
      ' cancel standard processing.
      e.Handled = True
    End Sub
    Ok, here's the problem. What I'm trying to do is have a small text box that will accept characters and automatically turn them into capital letters. However, when I try to erase characters using the back-space key, that doesn't work at all. What seems to be the problem?
    Here are the rules, you must obey them or the gender bender will get you.

    And if you ever think of posting without code-tags, the evil monkey will come after you.

  2. #2
    Join Date
    Apr 2000
    Location
    Dorado, P.R.
    Posts
    221

    Re: Converting characters to upper-case...

    Hi;

    Use LostFocus instead

    text1.text = ucase(text1.text)

  3. #3
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Converting characters to upper-case...

    This code should help you in trapping the backspace..
    Code:
    'If keypressed is Backspace, don't do nothing
    If e.KeyChar = vbBack Then
    	Exit Sub
    End If

  4. #4
    Join Date
    May 2005
    Location
    Mumbai, India
    Posts
    7

    Re: Converting characters to upper-case...

    if your only requirement is uppercassing of all characters entered then try setting the 'CharacterCasing' property of the textbox to 'Upper'.

  5. #5
    Join Date
    Apr 2004
    Location
    In the back seat of New Horizons.
    Posts
    1,238

    Re: Converting characters to upper-case...

    Quote Originally Posted by adcomp
    Hi;

    Use LostFocus instead

    text1.text = ucase(text1.text)
    That prevents me from inputting anything at all...
    Here are the rules, you must obey them or the gender bender will get you.

    And if you ever think of posting without code-tags, the evil monkey will come after you.

  6. #6
    Join Date
    Apr 2004
    Location
    In the back seat of New Horizons.
    Posts
    1,238

    Re: Converting characters to upper-case...

    Quote Originally Posted by sanjay13
    if your only requirement is uppercassing of all characters entered then try setting the 'CharacterCasing' property of the textbox to 'Upper'.
    Geez, I can't believe I missed that. Thanks .
    Here are the rules, you must obey them or the gender bender will get you.

    And if you ever think of posting without code-tags, the evil monkey will come after you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured