Re: Capture ESC Key for Dialog in wxEuphoria
- Posted by ghaberek (admin) Jun 18, 2012
- 1697 views
The library will handle this for you automatically as long as you have a button with wxID_CANCEL.
You can either create the buttons manually, or use a button sizer and create them automatically.
-- dialog_test1.exw include "wxeu/wxeud.e" constant frmMain = create( wxFrame, {0, -1, "Dialog Test", -1, -1, 320, 240} ) constant pnlMain = create( wxPanel, {frmMain} ) constant btnOpen = create( wxButton, {pnlMain, -1, "&Show dialog", 10, 10, 75, 23} ) constant txtOutput = create( wxTextCtrl, {pnlMain, -1, "", 10, 40, 284, 154, wxTE_MULTILINE+wxTE_READONLY} ) constant dlgDialog = create( wxDialog, {0, -1, "Dialog", -1, -1, 480, 360} ) constant btnOK = create( wxButton, {dlgDialog, wxID_OK, "OK", 10, 10, 75, 23} ) constant btnCancel = create( wxButton, {dlgDialog, wxID_CANCEL, "Cancel", 95, 10, 75, 23} ) procedure btnOpen_onClick( atom this, atom event_type, atom id, atom event ) sequence text if show_modal(dlgDialog) = wxID_OK then text = "result = OK\r\n" else text = "result = Cancel\r\n" end if append_text( txtOutput, text ) end procedure set_event_handler( btnOpen, -1, wxEVT_COMMAND_BUTTON_CLICKED, routine_id("btnOpen_onClick") ) wxMain( frmMain )
-- dialog_test2.exw include "wxeu/wxeud.e" constant frmMain = create( wxFrame, {0, -1, "Dialog Test", -1, -1, 320, 240} ) constant pnlMain = create( wxPanel, {frmMain} ) constant btnOpen = create( wxButton, {pnlMain, -1, "&Show dialog", 10, 10, 75, 23} ) constant txtOutput = create( wxTextCtrl, {pnlMain, -1, "", 10, 40, 284, 154, wxTE_MULTILINE+wxTE_READONLY} ) constant dlgDialog = create( wxDialog, {0, -1, "Dialog", -1, -1, 480, 360} ) constant pnlDialog = create( wxPanel, {dlgDialog} ) constant dlgSizer = create( wxBoxSizer, {wxVERTICAL} ) constant btnSizer = create_button_sizer( dlgDialog, wxOK+wxCANCEL ) add_window_to_sizer( dlgSizer, pnlDialog, 1, wxGROW, 0 ) add_sizer_to_sizer( dlgSizer, btnSizer, 0, wxGROW+wxBOTTOM, 4 ) set_sizer( dlgDialog, dlgSizer ) procedure btnOpen_onClick( atom this, atom event_type, atom id, atom event ) sequence text if show_modal(dlgDialog) = wxID_OK then text = "result = OK\r\n" else text = "result = Cancel\r\n" end if append_text( txtOutput, text ) end procedure set_event_handler( btnOpen, -1, wxEVT_COMMAND_BUTTON_CLICKED, routine_id("btnOpen_onClick") ) wxMain( frmMain )
Also, check out wxAboutDialogInfo for an easy way to make an "about" dialog (which it seems like you're trying to do).
-Greg