Page 1 of 1

Connecting Events

Posted: Thu Aug 16, 2012 3:37 pm
by eriX
Hi everybody!

I have one wxEdit field and one BitmapButton in my project.
If the user types in wxEdit and presses the return-key the function of the Bitmap shall become started.

I thought I could create a function to check each KeyEvent for return and call the function of my BitmapButton... but I've got some trouble at starting the BitmapButton function...

Code: Select all

void PressReturn(wxKeyEvent& event) 
   if(event.GetKeyCode() == WXK_RETURN) 
      TrainingFrm::WxBitmapButton1Click0(); // What must stand here?

void TrainingFrm::CreateGUIControls()
	wxInitAllImageHandlers();   //Initialize graphic format handlers

	WxPanel2 = new wxPanel(WxPanel1, ID_WXPANEL2, wxPoint(0, 471), wxSize(800, 105));

	WxEdit1 = new wxTextCtrl(WxPanel2, ID_WXEDIT1, wxT(""), wxPoint(285, 40), wxSize(365, 35), 0, wxDefaultValidator, wxT("WxEdit1"));
	WxEdit1->SetFont(wxFont(20, wxSWISS, wxNORMAL, wxNORMAL, false));

	wxBitmap WxBitmapButton1_BITMAP (wxT("gfx/button/btn_start_100x35.png"), wxBITMAP_TYPE_PNG);
	WxBitmapButton1 = new wxBitmapButton(WxPanel2, ID_WXBITMAPBUTTON1, WxBitmapButton1_BITMAP, wxPoint(650, 40), wxSize(100, 35), wxBU_AUTODRAW, wxDefaultValidator, wxT("WxBitmapButton1"));

	WxEdit1->Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(PressReturn)); 

void TrainingFrm::WxBitmapButton1Click0(wxCommandEvent& event)
    // MY CODE

Most of my code is auto-generated by wxDevC++

Thank you

Re: Connecting Events

Posted: Thu Aug 16, 2012 3:50 pm
by DavidHart
Hi Eric,

On a quick look:
WxEdit1->Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(PressReturn));
you get both the handler part and the eventSink parameter wrong. Search the forum for Connect() and you'll get lots of examples of how to do it correctly; or look at the wxEventHandler::Connect doc.

Meanwhile, consider instead using the wxTE_PROCESS_ENTER style flag and catching wxEVT_COMMAND_TEXT_ENTER. See



Re: Connecting Events

Posted: Thu Aug 16, 2012 5:37 pm
by eriX
Thank you for your advice!

I hope I've done it right?! Well, I guess it is right, because it works :D

Code: Select all

WxEdit1 = new wxTextCtrl(WxPanel2, ID_WXEDIT1, wxT(""), wxPoint(285, 40), wxSize(365, 35), wxTE_PROCESS_ENTER, wxDefaultValidator, wxT("WxEdit1"));
WxEdit1->Connect(wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler(TrainingFrm::WxBitmapButton1Click0), NULL, this);