Focus

Discussion in 'Questions (Windows Mobile)' started by pmu5757, Mar 21, 2008.

  1. pmu5757

    pmu5757 Member Licensed User

    Hello !
    First, excuse the poor english of a frenchy...

    I'm making a program that ask questions to the user.
    The user must type the answer in a textbox, and then click an OK button to check if the answer is right or not.
    To make the answer easier to type, I've set the focus on the answer textbox.
    But it's impossible for the user to type enter instead ok clicking ok because the focus is not on the ok button.
    Does it exist a solution to make it possible ?

    Thank you

    Pascal.
     
  2. willisgt

    willisgt Active Member Licensed User

    The solution is to catch each keypress as the user types text into the box. If and when the user presses the Enter key, simply call the same subroutine that would be called if the user had clicked on the button.

    Code:
    sub Textbox1_KeyPress( pKey )

       
    if pKey = Asc13 ) then Button1_Click   ' 13 = the Enter key, if I remember correctly

    end sub

    sub Button1_Click

       
    msgbox"Hello, World!" )

    end sub
     
    Last edited: Mar 21, 2008
  3. pmu5757

    pmu5757 Member Licensed User

    It works very well, thank you.
     
Loading...