[Gambas-user] closing form with esc
Rob
sourceforge-raindog2 at ...94...
Tue Mar 16 21:13:47 CET 2004
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
More information about the User
mailing list