How to clear client area or replace sizers and controls on a panel

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.
PaulUK
Knows some wx things
Knows some wx things
Posts: 43
Joined: Wed Nov 18, 2020 12:55 pm

How to clear client area or replace sizers and controls on a panel

Post by PaulUK »

I've been making some progress with my wxWidgets project and decided to go with a ribbon menu to choose from a number of independent calculator and simulation programs that would be shown in the main window frame. I have successfully been able to connect ribbon icons to event functions. It could equally be a toolbar by the way.

The problem I have now is how do I reset and place controls and sizers on the window when switching between programs in my app. Do I need a new panel for each independent calculator app, or does the panel need to be cleared and reset in some way.

I tried simply to create a new panel and sizers in an event function, but they get added to the original one created in the main frame definition. Any advice would be appreciated. Thank you.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to clear client area or replace sizers and controls on a panel

Post by doublemax »

The easiest way would be to have a separate panel for each calculator/simulation, create them all at once when the program starts, and put them into a wxSimpleBook, so that only one is visible at a time.
I tried simply to create a new panel and sizers in an event function, but they get added to the original one created in the main frame definition.
That should also work, but without seeing code, it's hard to tell what you did wrong.
Use the source, Luke!
PaulUK
Knows some wx things
Knows some wx things
Posts: 43
Joined: Wed Nov 18, 2020 12:55 pm

Re: How to clear client area or replace sizers and controls on a panel

Post by PaulUK »

Since the last posts I have been trying to get panels to be shown or to hidden whenever an icon/button is clicked on. These buttons are on a ribbon and I tested them to work fine so far with a message that pops up to confirm that I clicked on an icon. I can create a panel, give it a colour and add it to a sizer. From with the MainWindow I can hide or show the panel, this works fine. However, my problem now is that when I try to hide or show a panel from within a function that is activated by a ribbon button click, nothing seems to happen.

Is this problem because I am trying to show or hide the panel from outside the MainWindow function? If so is there a way to achieve what I want whenever an icon is clicked and a OnXXXButton event is called?

Here is the MainWindow.cpp file. The function "void MainWindow::OnMicrostripButton(wxRibbonButtonBarEvent& evt)" is where I'd like to hide the default panel and show a new one with its own controls. Near the bottom of MainWindow is where I was trying to show and hide the default panel by commenting out and uncommenting various lines. I hope that someone can help with this issue. Thank you.

The function "void MainWindow::OnCPWButton(wxRibbonButtonBarEvent& evt)" is a mess and doesn't do what I want either.

Code: Select all

#include "MainWindow.h"
#include <cmath>
#include "dish32.xpm"

// Static Event Table
wxBEGIN_EVENT_TABLE(MainWindow, wxFrame)
    EVT_TEXT_ENTER(wxID_ANY, MainWindow::OnRadiusEntered)
    // Ribbon menu buttons
    EVT_RIBBONBUTTONBAR_CLICKED(ID_MICROSTRIP, MainWindow::OnMicrostripButton)
    EVT_RIBBONBUTTONBAR_CLICKED(ID_CPW, MainWindow::OnCPWButton)
    EVT_RIBBONBUTTONBAR_CLICKED(ID_CPW_G, MainWindow::OnCPW_GButton)
    EVT_RIBBONBUTTONBAR_CLICKED(ID_STRIPLINE, MainWindow::OnStriplineButton)
    EVT_RIBBONBUTTONBAR_CLICKED(ID_COUPLED_STRIPLINE, MainWindow::OnCoupled_StriplineButton)



wxEND_EVENT_TABLE()

wxStaticText *EnterRadius;
wxTextCtrl *RadiusEntered;
wxStaticText *RadiusIs;
wxTextCtrl *AreaResult;
wxSizer* sizer = new wxBoxSizer(wxVERTICAL);
wxSizer* panelSizer = new wxBoxSizer(wxVERTICAL);

MainWindow::MainWindow(wxWindow *parent,
		wxWindowID id,
		const wxString& title,
		const wxPoint& pos,
		const wxSize& size,
		long style,
		const wxString& name)
	:wxFrame(parent, id, title, pos, wxSize(1024, 768), style, name)
{
    wxPanel *panel = new wxPanel(this, -1);
    panel->SetBackgroundColour(wxColor(000, 000, 000));



    // Set frame icon
    wxIcon frameicon(dish32_xpm);
    SetIcon(frameicon);

    // Ribbon
    ribbonBar = new wxRibbonBar(this, -1, wxDefaultPosition, wxDefaultSize, wxRIBBON_BAR_FLOW_HORIZONTAL
                                | wxRIBBON_BAR_SHOW_PAGE_LABELS
                                | wxRIBBON_BAR_SHOW_PANEL_EXT_BUTTONS
                                | wxRIBBON_BAR_SHOW_TOGGLE_BUTTON
                                );

    tlinesRibbonPage = new wxRibbonPage(ribbonBar, wxID_ANY, wxT("TLine Calculators"), wxNullBitmap);
    radomeRibbonPage = new wxRibbonPage(ribbonBar, wxID_ANY, wxT("Radome Analysis"), wxNullBitmap);
    hornsRibbonPage = new wxRibbonPage(ribbonBar, wxID_ANY, wxT("Horn Analysis"), wxNullBitmap);
    sinuousRibbonPage = new wxRibbonPage(ribbonBar, wxID_ANY, wxT("Sinuous & Spiral"), wxNullBitmap);
    reflectorsRibbonPage = new wxRibbonPage(ribbonBar, wxID_ANY, wxT("Reflector Analysis"), wxNullBitmap);


    planartlinesRibbonPanel = new wxRibbonPanel(tlinesRibbonPage, wxID_ANY, wxT("Planar TLines"), wxNullBitmap,
                                        wxDefaultPosition, wxDefaultSize,
                                        wxRIBBON_PANEL_NO_AUTO_MINIMISE);

    wgRibbonPanel = new wxRibbonPanel(tlinesRibbonPage, wxID_ANY, wxT("Waveguide"), wxNullBitmap,
                                        wxDefaultPosition, wxDefaultSize,
                                        wxRIBBON_PANEL_NO_AUTO_MINIMISE);

    coaxRibbonPanel = new wxRibbonPanel(tlinesRibbonPage, wxID_ANY, wxT("Coaxial"), wxNullBitmap,
                                        wxDefaultPosition, wxDefaultSize,
                                        wxRIBBON_PANEL_NO_AUTO_MINIMISE);

    radomeRibbonPanel = new wxRibbonPanel(radomeRibbonPage, wxID_ANY, wxT("Radome"), wxNullBitmap,
                                        wxDefaultPosition, wxDefaultSize,
                                        wxRIBBON_PANEL_NO_AUTO_MINIMISE);

    planartlinesRibbonButtonBar = new wxRibbonButtonBar(planartlinesRibbonPanel);
    wgRibbonButtonBar = new wxRibbonButtonBar(wgRibbonPanel);
    coaxRibbonButtonBar = new wxRibbonButtonBar(coaxRibbonPanel);
    radomeRibbonButtonBar = new wxRibbonButtonBar(radomeRibbonPanel);


    // Planar TLine Tools
    planartlinesRibbonButtonBar->AddButton(ID_MICROSTRIP, wxT("Microstrip"),
                                   wxArtProvider::GetBitmap(wxART_ADD_BOOKMARK, wxART_TOOLBAR, wxSize(32,32)));

    planartlinesRibbonButtonBar->AddButton(ID_CPW, wxT("CPW"),
                                   wxArtProvider::GetBitmap(wxART_ADD_BOOKMARK, wxART_TOOLBAR, wxSize(32,32)));

    planartlinesRibbonButtonBar->AddButton(ID_CPW_G, wxT("CPW-G"),
                                   wxArtProvider::GetBitmap(wxART_ADD_BOOKMARK, wxART_TOOLBAR, wxSize(32,32)));

    planartlinesRibbonButtonBar->AddButton(ID_STRIPLINE, wxT("Stripline"),
                                   wxArtProvider::GetBitmap(wxART_ADD_BOOKMARK, wxART_TOOLBAR, wxSize(32,32)));

    planartlinesRibbonButtonBar->AddButton(ID_COUPLED_STRIPLINE, wxT("Coupled Stripline"),
                                   wxArtProvider::GetBitmap(wxART_ADD_BOOKMARK, wxART_TOOLBAR, wxSize(32,32)));
    // Waveguide Tools
    wgRibbonButtonBar->AddButton(wxID_ANY, wxT("Rectangular Waveguide"),
                                   wxArtProvider::GetBitmap(wxART_QUESTION, wxART_TOOLBAR, wxSize(32,32)));

    wgRibbonButtonBar->AddButton(wxID_ANY, wxT("Circular Waveguide"),
                                   wxArtProvider::GetBitmap(wxART_QUESTION, wxART_TOOLBAR, wxSize(32,32)));

    wgRibbonButtonBar->AddButton(wxID_ANY, wxT("Double Ridge Waveguide"),
                                   wxArtProvider::GetBitmap(wxART_QUESTION, wxART_TOOLBAR, wxSize(32,32)));

    wgRibbonButtonBar->AddButton(wxID_ANY, wxT("Waveguide Modes"),
                                   wxArtProvider::GetBitmap(wxART_QUESTION, wxART_TOOLBAR, wxSize(32,32)));

    wgRibbonButtonBar->AddButton(wxID_ANY, wxT("Waveguide Dimensions"),
                                   wxArtProvider::GetBitmap(wxART_QUESTION, wxART_TOOLBAR, wxSize(32,32)));

    coaxRibbonButtonBar->AddButton(wxID_ANY, wxT("Coaxial Impedance"),
                                   wxArtProvider::GetBitmap(wxART_QUESTION, wxART_TOOLBAR, wxSize(32,32)));

    //Radome Tools
    radomeRibbonButtonBar->AddButton(wxID_ANY, wxT("Multi-Layer Radome Analysis"),
                                   wxArtProvider::GetBitmap(wxART_QUESTION, wxART_TOOLBAR, wxSize(32,32)));

    radomeRibbonButtonBar->AddButton(wxID_ANY, wxT("Dielectric Properties"),
                                   wxArtProvider::GetBitmap(wxART_QUESTION, wxART_TOOLBAR, wxSize(32,32)));



    ribbonBar->AddPageHighlight(ribbonBar->GetPageCount());
    ribbonBar->Realise();


    // Set layout with sizers
    wxSizer* sizer = new wxBoxSizer(wxVERTICAL);
    sizer->Add(ribbonBar, 0, wxEXPAND);

    wxSizer* panelSizer = new wxBoxSizer(wxVERTICAL);
    panelSizer->Add(panel, 1, wxEXPAND);

   // panelSizer->Show(panel);

    sizer->Add(panelSizer, 1, wxEXPAND);
    panelSizer->Hide(panel);


  SetSizer(sizer);

 // panelSizer->Show(panel);

    Center();

    // Set status bar
    CreateStatusBar(2);
    SetStatusText(_T("Status Text 1"), 0);
    SetStatusText(_T("Status Text 2"), 1);

//panelSizer->Show(panel);  Testing Show(panel) within MainWindow setup and it works here.
//panel->Show();
}

// Functions Here

void MainWindow::OnMicrostripButton(wxRibbonButtonBarEvent& evt)
{
 MainWindow::panel->Show();
    //panelSizer->Show(panel);
    panel->Refresh();
}

void MainWindow::OnCPWButton(wxRibbonButtonBarEvent& evt)
{
  //wxMessageBox("MainWindow::OnCPWButton");

  wxPanel *panelCPW = new wxPanel(this, -1);
  panelCPW->SetBackgroundColour(wxColor(50, 200, 200));
//  sizer->Add(panelCPW, 1, wxEXPAND);
//  //SetSizer(sizer);
//  panelMicrostrip->Hide();
//  panelCPW->Show();
//  panelCPW->Refresh();
//  SetSizer(sizer);

}

void MainWindow::OnCPW_GButton(wxRibbonButtonBarEvent& evt)
{
  wxMessageBox("MainWindow::OnCPW_GButton");
}

void MainWindow::OnStriplineButton(wxRibbonButtonBarEvent& evt)
{
  wxMessageBox("MainWindow::OnStriplineButton");
}

void MainWindow::OnCoupled_StriplineButton(wxRibbonButtonBarEvent& evt)
{
  wxMessageBox("MainWindow::OnCoupled_StriplineButton");
}

PaulUK
Knows some wx things
Knows some wx things
Posts: 43
Joined: Wed Nov 18, 2020 12:55 pm

Re: How to clear client area or replace sizers and controls on a panel

Post by PaulUK »

I hope it's ok to bump this thread.
I still haven't solved the problem of showing / hiding or setting up controls on a panel from a function outside of the "MainWindow" function. Just a reminder, I want to be able to click on icons of a ribbon icon bar, and for each one to show a panel in the frame with controls related to that icon. Each icon clicked should show only the controls related to that "sub program" chosen. Please can anyone more experience tell me if this can be done and how. When I try to just show or hide an empty panel, I can't seem to do it from a function which is activated with an event from a mouse click on the icon. However I can show and hide a panel with code in the "MainWindow" section of code.

The event table seems fine and I can display a popup message box on icon clicks. So at least that is working.
Thank you.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to clear client area or replace sizers and controls on a panel

Post by doublemax »

As the code doesn't compile as it is, i can't play around with it, which makes providing a solution mode difficult. And if it's much code, people might not be motivated to look into it at all.

If you don't want to use a wxSimpleBook (which you should), you have to:
- store the pointers of all panels you want to show / hide. Otherwise you won't be able to show / hide them
- if you create a new panel at runtime, you need to put it into the sizer, and then hide all other panels

Relevant code parts:

Code: Select all

wxStaticText *EnterRadius;
wxTextCtrl *RadiusEntered;
wxStaticText *RadiusIs;
wxTextCtrl *AreaResult;
wxSizer* sizer = new wxBoxSizer(wxVERTICAL);
wxSizer* panelSizer = new wxBoxSizer(wxVERTICAL);
Don't use globale variables, turn them into member variables.

Code: Select all

    wxPanel *panel = new wxPanel(this, -1);
    panel->SetBackgroundColour(wxColor(000, 000, 000));
You need to store the wxPanel pointer in a member variable

Code: Select all

    wxSizer* panelSizer = new wxBoxSizer(wxVERTICAL);
    panelSizer->Add(panel, 1, wxEXPAND);
You need to store the wxBoxSizer pointer in a member variable, because you'll need it in the button click handler

Code: Select all

  wxPanel *panelCPW = new wxPanel(this, -1);
  panelCPW->SetBackgroundColour(wxColor(50, 200, 200));
You need to store the wxPanel pointer in a member variable. And you should make sure that you don't create a new panel if another instance of the same panel already exists (unless you want that to be possible).
add panelCPW to the panelSizer
hide all other panels in the sizer
call Layout() on the sizer

I highly recommend to use wxSimpleBook which makes managing all this much easier.
Use the source, Luke!
PaulUK
Knows some wx things
Knows some wx things
Posts: 43
Joined: Wed Nov 18, 2020 12:55 pm

Re: How to clear client area or replace sizers and controls on a panel

Post by PaulUK »

Thank you for the reply, If I attach the few files associated with this project would you mind having a quick look and showing how to do this? I'm struggling a bit with this coming from a C background and previously VB. I'm using Codeblocks. I'm open to using wxSimpleBook but haven't yet found any examples to use as a guide. Thank you.

Just to point out that the ribbon toolbar was based on the example in the samples with my own changes off course. I will check the samples about the wxSimplebook, and would I be right about assuming that a panel and controls can be assigned to various "pages" or screens of the wxSimplebook?

I'm trying to make an interface to my program simple to use for the user so that different sub programs can be easily selected from the ribbon icons.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to clear client area or replace sizers and controls on a panel

Post by doublemax »

If I attach the few files associated with this project would you mind having a quick look and showing how to do this?
Sure, if it's not too much hazzle to get it to compile :)
Use the source, Luke!
PaulUK
Knows some wx things
Knows some wx things
Posts: 43
Joined: Wed Nov 18, 2020 12:55 pm

Re: How to clear client area or replace sizers and controls on a panel

Post by PaulUK »

It compiles fine on my machine with my wxWidgets setup, I would hope that it compiles fine on yours, I'll attach the files tomorrow. Thank you, I appreciate it. The GUI is the bottleneck for my project at the moment. Once I can start adding panels with controls I'll be able to make rapid progress.
PaulUK
Knows some wx things
Knows some wx things
Posts: 43
Joined: Wed Nov 18, 2020 12:55 pm

Re: How to clear client area or replace sizers and controls on a panel

Post by PaulUK »

I have attached the CodeBlocks project. There are two cpp and two header files with a number of image recourses. I deleted the Debug and Release folders to take less space. I hope that it compiles and if you could show what you meant in the previous messages. I'd really appreciate it.
ProjectTemplateRibbon.zip
CodeBlocks Project
(94.53 KiB) Downloaded 48 times
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to clear client area or replace sizers and controls on a panel

Post by doublemax »

Here you go. I just added 3 colored panel and put them in a wxSimplebook. You can switch between the panels with the first 3 buttons on the ribbonbar.
Attachments
MainWindow.h
(1.99 KiB) Downloaded 72 times
MainWindow.cpp
(8.26 KiB) Downloaded 65 times
Use the source, Luke!
PaulUK
Knows some wx things
Knows some wx things
Posts: 43
Joined: Wed Nov 18, 2020 12:55 pm

Re: How to clear client area or replace sizers and controls on a panel

Post by PaulUK »

Thank you very much, I will try it this evening and report back how I get on. It's very much appreciated. :D
PaulUK
Knows some wx things
Knows some wx things
Posts: 43
Joined: Wed Nov 18, 2020 12:55 pm

Re: How to clear client area or replace sizers and controls on a panel

Post by PaulUK »

Since the last post, I can see how the various panels of the wxSimpleBook are called and this is a really nice solution. My next problem is using sizers to place controls and to display them properly.
I see that there is a SetSizer for the simplebook/main frame sizer to show the simplebook panel and ribbon menu. However, I cannot seem to get multiple buttons to show according to their sizers. I add buttons to sizers within the first panel, but the buttons "ok" and "cancel" sit on top of each other and in the top left corner which is the default. This implies that the sizers are not set. If I try to use SetSizer on the panel, then the application does not run.

My main question here is how do I layout controls on the multiple panels of wxSimpleBook and set them all accordingly with sizers. Is it true that SetSizer can be called only once? Thank you.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to clear client area or replace sizers and controls on a panel

Post by doublemax »

Can you show some code, ideally based on the sample i posted?
Use the source, Luke!
PaulUK
Knows some wx things
Knows some wx things
Posts: 43
Joined: Wed Nov 18, 2020 12:55 pm

Re: How to clear client area or replace sizers and controls on a panel

Post by PaulUK »

doublemax wrote: Wed Mar 23, 2022 11:26 am Can you show some code, ideally based on the sample i posted?
I will post the two snippets here. One trying to set the sizing before and then after setting the m_red_panel to be a panel in the wxSimpleBook. I had no success with either. The sizer with the "OK" and "Cancel" buttons are from one of the tutorials on sizer layouts. I hope it makes some sense. The Ok and Cancel buttons should be aligned to the bottom right of the window. Once I can do this I should be able to arrange each panel as I wish, for each sub-program in my application. It would be good to know how to add controls and sizers in a way that allows each panel in the wxSimpleBook be seperately controlled. Thank you.

Code: Select all

// Inserting sizers and controls before adding m_red_panel to m_panel_book

    // Set layout with sizers
    wxSizer* sizer = new wxBoxSizer(wxVERTICAL);
    sizer->Add(ribbonBar, 0, wxEXPAND);

    m_panel_book = new wxSimplebook(this, wxID_ANY);

    wxPanel *m_red_panel = new wxPanel(m_panel_book, wxID_ANY);
    m_red_panel->SetBackgroundColour(*wxRED);

    wxSizer* msl_v_sizer = new wxBoxSizer(wxVERTICAL);
    wxSizer* msl_h_sizer1 = new wxBoxSizer(wxHORIZONTAL);
    wxSizer* msl_h_sizer2 = new wxBoxSizer(wxHORIZONTAL);
    wxButton *ok = new wxButton(m_red_panel, -1, wxT("OK"));
    wxButton *cancel = new wxButton(m_red_panel, -1, wxT("Cancel"));

    msl_h_sizer1->Add(m_red_panel);
    msl_v_sizer->Add(msl_h_sizer1, 1, wxEXPAND);
    msl_h_sizer2->Add(ok);
    msl_h_sizer2->Add(cancel);
    msl_v_sizer->Add(msl_h_sizer2, 0, wxALIGN_RIGHT | wxRIGHT | wxBOTTOM, 10);
    //m_red_panel->SetSizer(msl_v_sizer);

    m_panel_book->AddPage( m_red_panel, "red panel" );



    wxPanel *m_green_panel = new wxPanel(m_panel_book, wxID_ANY);
    m_green_panel->SetBackgroundColour(*wxGREEN);
    m_panel_book->AddPage( m_green_panel, "green panel" );

    wxPanel *m_blue_panel = new wxPanel(m_panel_book, wxID_ANY);
    m_blue_panel->SetBackgroundColour(*wxBLUE);
    m_panel_book->AddPage( m_blue_panel, "blue panel" );

    sizer->Add( m_panel_book, 1, wxEXPAND);

    SetSizer(sizer);

    Center();

    // Set status bar
    CreateStatusBar(2);
    SetStatusText(_T("Status Text 1"), 0);
    SetStatusText(_T("Status Text 2"), 1);

... and after

Code: Select all

// Inserting sizers and controls after adding m_red_panel to m_panel_book

    // Set layout with sizers
    wxSizer* sizer = new wxBoxSizer(wxVERTICAL);
    sizer->Add(ribbonBar, 0, wxEXPAND);

    m_panel_book = new wxSimplebook(this, wxID_ANY);

    wxPanel *m_red_panel = new wxPanel(m_panel_book, wxID_ANY);
    m_red_panel->SetBackgroundColour(*wxRED);
    m_panel_book->AddPage( m_red_panel, "red panel" );
    
    wxSizer* msl_v_sizer = new wxBoxSizer(wxVERTICAL);
    wxSizer* msl_h_sizer1 = new wxBoxSizer(wxHORIZONTAL);
    wxSizer* msl_h_sizer2 = new wxBoxSizer(wxHORIZONTAL);
    wxButton *ok = new wxButton(m_red_panel, -1, wxT("OK"));
    wxButton *cancel = new wxButton(m_red_panel, -1, wxT("Cancel"));

    msl_h_sizer1->Add(m_red_panel);
    msl_v_sizer->Add(msl_h_sizer1, 1, wxEXPAND);
    msl_h_sizer2->Add(ok);
    msl_h_sizer2->Add(cancel);
    msl_v_sizer->Add(msl_h_sizer2, 0, wxALIGN_RIGHT | wxRIGHT | wxBOTTOM, 10);
    //m_red_panel->SetSizer(msl_v_sizer);


    wxPanel *m_green_panel = new wxPanel(m_panel_book, wxID_ANY);
    m_green_panel->SetBackgroundColour(*wxGREEN);
    m_panel_book->AddPage( m_green_panel, "green panel" );

    wxPanel *m_blue_panel = new wxPanel(m_panel_book, wxID_ANY);
    m_blue_panel->SetBackgroundColour(*wxBLUE);
    m_panel_book->AddPage( m_blue_panel, "blue panel" );

    sizer->Add( m_panel_book, 1, wxEXPAND);

    SetSizer(sizer);

    Center();

    // Set status bar
    CreateStatusBar(2);
    SetStatusText(_T("Status Text 1"), 0);
    SetStatusText(_T("Status Text 2"), 1);
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to clear client area or replace sizers and controls on a panel

Post by doublemax »

Code: Select all

    wxPanel *m_red_panel = new wxPanel(m_panel_book, wxID_ANY);

      /* add controls to red panel - start */
      wxBoxSizer *red_main_sizer = new wxBoxSizer(wxVERTICAL);
      red_main_sizer->Add( new wxButton(m_red_panel, wxID_ANY, "SOME BUTTON"), 0, wxALL, 4);
      
      // this stretchable space "pushes" the following horizontal sizer to the bottom of the panel
      red_main_sizer->AddStretchSpacer(1);

        wxBoxSizer *h_sizer = new wxBoxSizer(wxHORIZONTAL);
        
        // this stretchable space "pushes" the following buttons to the right edge
        h_sizer->AddStretchSpacer(1);
        h_sizer->Add( new wxButton(m_red_panel, wxID_CANCEL, "Cancel"), 0, wxALL, 4);
        h_sizer->Add( new wxButton(m_red_panel, wxID_OK, "OK"), 0, wxALL, 4);
      red_main_sizer->Add( h_sizer, 0, wxEXPAND, 0);
    m_red_panel->SetSizer(red_main_sizer);

    /* add controls to red panel - end */
    m_red_panel->SetBackgroundColour(*wxRED);
    m_panel_book->AddPage( m_red_panel, "red panel" );
The panels are already managed by the wxSimpleBook, so it doesn't make any sense to put them into a sizer.

I suggest you look at http://neume.sourceforge.net/sizerdemo/ and try to get a deeper understanding of how sizers work.
Use the source, Luke!
Post Reply