Connecting Events Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
eriX
Experienced Solver
Experienced Solver
Posts: 84
Joined: Wed Feb 04, 2009 2:08 pm
Location: Germany
Contact:

Connecting Events

Post by eriX » Thu Aug 16, 2012 3:37 pm

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?
   } 
   event.Skip(); 
}


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

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

	WxEdit1 = new wxTextCtrl(WxPanel2, ID_WXEDIT1, wxT(""), wxPoint(285, 40), wxSize(365, 35), 0, wxDefaultValidator, wxT("WxEdit1"));
	WxEdit1->SetBackgroundColour(wxColour(255,255,255));
	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
-Eric

DavidHart
Site Admin
Site Admin
Posts: 3967
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: Connecting Events

Post by DavidHart » Thu Aug 16, 2012 3:50 pm

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 http://docs.wxwidgets.org/2.8.12/wx_wxtextctrl.html.

Regards,

David

eriX
Experienced Solver
Experienced Solver
Posts: 84
Joined: Wed Feb 04, 2009 2:08 pm
Location: Germany
Contact:

Re: Connecting Events

Post by eriX » Thu Aug 16, 2012 5:37 pm

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);

Post Reply