[Gambas-user] closing form with esc
Benoit Minisini
gambas at ...1...
Tue Mar 16 23:55:07 CET 2004
On Tuesday 16 March 2004 21:13, Rob wrote:
> On Tuesday 16 March 2004 14:52, -fiero - wrote:
> > can i close a form pressing the "ESC" key ???
>
> Yes, but not with the vb code you posted.
>
> Make a button to close the form... doesn't matter what the button
> says on it.... put "me.close" in its Click event, and set its
> Cancel property to true. Then that button's click event will be
> fired when the user presses Esc, and the form will close.
>
> > the keyPress and keyDown event seems to not operate in a form,
> > why ?
>
> Currently, in gambas, each event only triggers one event handler,
> and if there is no event handler associated with the control
> that threw the event, it does not get passed up the hierarchy to
> the parent form. That is to say, the only way the form should
> get keypress events is if there are no controls on the form or
> they all somehow lose the focus.
>
> I'd like to see a KeyPreview property like in VB, PerlQt and
> Delphi/Kylix, but I can also understand why Benoit wouldn't want
> to do this. So meanwhile you can work around it by either doing
> the above (for the specific case of wanting to close the form
> with Esc) or with some nasty code, as follows:
>
> public sub Form_Keypress
> ' do something here
> end
>
> public sub Textbox1_Keypress
> ' do whatever the textbox needs to do, then....
> Form_Keypress
> end
>
> You need to add that Form_Keypress to the Keypress event handler
> of EVERY control that can possibly get the focus.
>
> However, there must be a different way to do this as well because
> the Gambas IDE is written in Gambas, yet in most places you can
> press F5 and the project runs despite Key.F5 being checked in
> only one place.
>
> Rob
>
This is undocumented feature: when a key is pressed, then it is propagated to
the application main window (the first that was opened) as an accelerator
key. Only the window menu sees it.
The KeyPreview feature of VB does not exist. I didn't think about it yet,
because I have no use of it. I don't know if implementing it is possible...
Regards,
--
Benoit Minisini
mailto:gambas at ...1...
More information about the User
mailing list