EVT_BUTTON event handling problem

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
stefi
In need of some credit
In need of some credit
Posts: 1
Joined: Thu Apr 20, 2017 6:38 pm

EVT_BUTTON event handling problem

Post by stefi »

Hi,

I've started learning wxWidget and have problem handling button events.
I've started to create a small app, and created a panel with a sizer and some buttons, and it appears well, but when click on the button I don't receive the event for some reason.

Code: Select all

#include <wx/wx.h>
class SidebarPanel : public wxPanel
{
public:
   SidebarPanel(wxWindow* parent);
   void onExit(wxCommandEvent& event);
private:
   wxButton* mConvertButton;
   wxButton* mExitButton;
   wxTextCtrl* mTextctrl;
   wxDECLARE_EVENT_TABLE();
};

wxBEGIN_EVENT_TABLE(SidebarPanel, wxPanel)
EVT_BUTTON(wxID_EXIT, SidebarPanel::onExit)
wxEND_EVENT_TABLE()

SidebarPanel::SidebarPanel(wxWindow* parent) :
   wxPanel(parent)
{
   wxColour col;
   col.Set(wxT("#4f5049"));
   SetBackgroundColour(col);
   
   wxGridSizer* sizer = new wxGridSizer(3,3,1,1);
   mConvertButton = new wxButton(this, wxID_CONVERT);
   mExitButton = new wxButton(this, wxID_EXIT);
   sizer->Add(mConvertButton, 1, wxALL);
   sizer->Add(mExitButton, 1, wxALL);
   SetSizerAndFit(sizer);
}
void SidebarPanel::onExit(wxCommandEvent& event)
{
   std::cout<<"DrawPane::onExit"<<std::cout;
   Close(TRUE);
}
Thanks for help in advance,
Stefi
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: EVT_BUTTON event handling problem

Post by ONEEYEMAN »

Hi,
Which OS/toolkit version?
Which wx version?

Thank you.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: EVT_BUTTON event handling problem

Post by doublemax »

I can't spot anything wrong. Try using wxLogMessage in onExit() to display a message.

The Close() will probably not do what you expect. As it will be called on a wxPanel it will not close the main window (which is probably what you intended to do).
Use the source, Luke!
Post Reply