[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Convenient way to parse Enter on a textbox?


TextBox and some other controls have an Activate event fired in a return
press.

Public Sub TextBox1_Activate()

  Button1.value =True

End

To get out of the event handler you could start your button click using a
timer.

BruceS


On Mon, 22 Sept 2025, 14:23 Admin, <admin@xxxxxxxxxx> wrote:

> Greetings good people of Gambas!
>
> This should be pretty common thing in visual programming to create a
> program that allows user to type something in a field and hit enter to
> make it work, send it, right? Like, in Chat clients or something.
>
> So it should be pretty easy to trace Enter key while some textbox is in
> focus and react to it, is it not?
>
> I have a program that has a textbox and a "send" button.
>
> But.
>
> It seems to me that even having a sub like <anything>_KeyPress() brings
> a lot of "entropy" in to my program. This routine seems to be an event
> handler which "destroys" any "wait"s in the program, does not allow an
> interface to redraw itself before moving on to some long task, and
> finally, it does not even work right away.
>
> For example, in my Send button Sub I call another form to appear and
> then do "wait 0.1" for the form to actually appear, then I do other
> stuff. And it works. But if I call Button_Click sub from a KeyPress
> event of the textbox, it is ignored, debug window shows a warning that
> there is no use to call wait while keypress is active and the new form
> is not shown until all the routine of button_click is over.
>
> The workaround I use now is to just button.setfocus on Enter keypress
> and then I expect user to press enter again. So it's basically two
> enters instead of one to send a string from a textbox. It works, but I
> feel stupid.
>
> I strongly believe that it should be done much, much easier since it is
> a common task, and that I just don't understand Gambas enough.
>
> Can you please teach me the right way?
>
> Dmitry.
>
>
>

References:
Convenient way to parse Enter on a textbox?Admin <admin@xxxxxxxxxx>