Difficulty with BIND Part 2 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
Nick
Experienced Solver
Experienced Solver
Posts: 53
Joined: Thu Apr 11, 2019 12:50 am

Difficulty with BIND Part 2

Post by Nick » Wed Mar 25, 2020 6:33 pm

I learned in the topic: forums.wxwidgets.org/viewtopic.php?f=1&t=46953
The command:

Code: Select all

FrmMain->Bind(wxEVT_SIZE, &MyProgram::OnSize, this);
And with it I set up the program below that works!

Code: Select all

 #include <wx/app.h>
 #include <wx/frame.h>
 #include <wx/panel.h>
 
 class MyProgram: public wxApp {
 public:
   wxFrame *FrmMain;

 private:
    void OnSize(wxSizeEvent &event);

   bool OnInit() {
      FrmMain = new wxFrame(NULL, wxID_ANY, "");
      FrmMain->Bind(wxEVT_SIZE, &MyProgram::OnSize, this);
      FrmMain->Show();
      return true;
    }
 };

 wxIMPLEMENT_APP(MyProgram);

 void MyProgram::OnSize(wxSizeEvent &event) {
   FrmMain->SetTitle(wxString::Format("J:%dx%d C:%dx%d", FrmMain->GetSize().y, FrmMain->GetSize().x, FrmMain->GetClientSize().y, FrmMain->GetClientSize().x));
 }
But if I add 1 TextCtrl to that program, the BIND command messes up the control display
Example of what I did below

Code: Select all

 #include <wx/app.h>
 #include <wx/frame.h>
 #include <wx/panel.h>
 #include <wx/textctrl.h>
 
 class MyProgram: public wxApp {
 public:
   wxFrame *FrmMain;

 private:
    void OnSize(wxSizeEvent &event);

   bool OnInit() {
      FrmMain = new wxFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxSize(320,60), wxCLOSE_BOX);

      wxPanel *Panel = new wxPanel(FrmMain);
      new wxTextCtrl(Panel, wxID_ANY, "Good Morning!", wxPoint(5,5), wxSize(300,30));
         
      FrmMain->Bind(wxEVT_SIZE, &MyProgram::OnSize, this);
      
      FrmMain->Show();
      return true;
    }
 };

 wxIMPLEMENT_APP(MyProgram);

 void MyProgram::OnSize(wxSizeEvent &event) {
   FrmMain->SetTitle(wxString::Format("J:%dx%d C:%dx%d", FrmMain->GetSize().y, FrmMain->GetSize().x, FrmMain->GetClientSize().y, FrmMain->GetClientSize().x));
 }
Image

If I take the BIND line it shows correctly: FrmMain->Bind(wxEVT_SIZE, &MyProgram::OnSize, this);
Image

How do I fix this?

User avatar
doublemax
Moderator
Moderator
Posts: 14613
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Difficulty with BIND Part 2

Post by doublemax » Wed Mar 25, 2020 7:51 pm

Call "event.Skip()" in the OnSize handler, so that the default behavior is executed, too.
Use the source, Luke!

Nick
Experienced Solver
Experienced Solver
Posts: 53
Joined: Thu Apr 11, 2019 12:50 am

Re: Difficulty with BIND Part 2

Post by Nick » Wed Mar 25, 2020 8:57 pm

doublemax wrote:
Wed Mar 25, 2020 7:51 pm
Call "event.Skip()" in the OnSize handler, so that the default behavior is executed, too.
It worked! I will study more about event.Skip ();
Thank you!

For others who will read this Post:
When I created the example, I declared the wxFrame wrong. Blocking his resizing. The correct way is:

Code: Select all

FrmMain = new wxFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxSize(320,60));

Post Reply