Textbox to textbox

Discussion in 'Questions (Windows Mobile)' started by kavka, Dec 21, 2007.

  1. kavka

    kavka Member Licensed User

    Hello!

    Help me solve the following problem:

    I have two textboxes. The number of digits in one textbox is two. When I enter the second digit in the first textbox I want that the second textbox gets focused. is that possible?

    :sign0085:

    kavkaa
     
  2. willisgt

    willisgt Active Member Licensed User

    Sure, it's possible.

    The most logical thing to do would be to catch this with the KeyPress event. There's a problem, though - the KeyPress event gets raised *before* the key you pressed actually gets added to the textbox. At least that's the behavior on my desktop and device.

    So I've been using a little workaround that involves a timer. Create your form, textbox1, textbox2, and timer1.

    In AppStart:

    Code:
    timer1.interval = 100   ' thats 100 milliseconds
    timer1.enabled = false
    and then:

    Code:
    sub textbox1_KeyPress( key )
       timer1.enabled = 
    true
    end sub

    sub timer1_Tick
       
    if StrLength( textbox1.text) >= 2 then textbox2.Focus
       timer1.enabled = 
    false
    end sub
    It comes close to a cheezy hack, but hey, it works for me.

    Gary

    :sign0025:
     
  3. agraham

    agraham Expert Licensed User

    You could use my ControlEvents library that adds "missing" events to B4PPC controls and catch the TextChanged event of the TextBox which occurs after the key press is added. Much better than cheesy hacks :) (Apologies willisgt!)

    http://www.basic4ppc.com/forum/showthread.php?t=934
     
  4. willisgt

    willisgt Active Member Licensed User

    Cheezy hackers of the world, unite!

    :sign0151:
     
  5. kavka

    kavka Member Licensed User

    agraham, can you help me out with this missing events. Do I just copy those three files in the library directory and that is that?
     
  6. agraham

    agraham Expert Licensed User

    Sounds like you need to learn how to use libraries. You should have downloaded the latest ControlEvents version from either Post #5 (.Net 2.0) or #6 (.NET1.0) from that thread. One of those files is a help file, the chm, the library is the dll - stick the help and the library in the Anywhere Software Libraries folder. Ignore and discard the cs file - you don't need it.

    Restart B4PPC - Desktop. The ControlEvents help should now show under Help - read it and the Main help about libraries.
     
Loading...