Focus

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.
 

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.

B4X:
sub Textbox1_KeyPress( pKey )

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

end sub

sub Button1_Click

   msgbox( "Hello, World!" )

end sub
 
Last edited:
Top