Uppercase !

Discussion in 'Questions (Windows Mobile)' started by superbabicka, Apr 9, 2008.

  1. superbabicka

    superbabicka Member Licensed User

    I know that this is stupid question but I'm agonize with... :sign0161:

    (I want to make desktop application)
    I have TextBox (Only One) And after key_press I want string automatically go to uppercase.
    I have this:

    Sub TextBox1_KeyPress(key)
    TextBox1.Text = StrToUpper(TextBox1.Text)
    End Sub

    So, when I push First Key, nothings happen - (lowercase), and when I push second key, then the First Key Is Uppercase, the CURSOR is on the beginning of the TextBox1 focus, and ONE FROM ANOTHER every next key is Uppercase, BUT MY WORDS IS TOPSY-TURVY ...

    Aaaaaaahhhhh :(

    Some Help...?

    Thx
     
  2. agraham

    agraham Expert Licensed User

    You have two problems here. Firstly you get the KeyPress event before that key is added to the textbox so it doesn't get uppercased. Secondly the insertion point is lost when you uppercase the string.

    The solution to the first is to use the new Door library http://www.basic4ppc.com/forum/showthread.php?t=2038 to catch the TextChanged event which occurs after the key is added. The solution to the second is to save and restore the insertion point.
     

    Attached Files:

    Last edited: Apr 9, 2008
  3. Erel

    Erel Administrator Staff Member Licensed User

    You should use the TextChanged event (with the Door library):
    Code:
    'obj is an Object, TextBox1ChangedEvent is an Event.
    Sub App_Start
        Form1.Show
        obj.New1(
    false)
        obj.FromControl(
    "textbox1")
        TextBox1ChangedEvent.New1( obj.Value,
    "TextChanged")
    End Sub

    Sub TextBox1ChangedEvent_NewEvent
        textbox1.text = StrToUpper(TextBox1.Text)
        textbox1.SelectionStart = StrLength(textbox1.text)
    End Sub
     
  4. agraham

    agraham Expert Licensed User

    :sign0162: Beat you this time Erel :) (but by only one minute!)
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    I can only say "great minds think alike" ;)
     
  6. superbabicka

    superbabicka Member Licensed User

    Thanks Boys !!!

    :sign0188:
     
Loading...