I'm making an application where after button press one panel changes to another. Everything is working except the layout. New panel is not in old place (right and expanded) but in top left corner over the button. Can you help me put new panel in old place?
testMain.cpp
Code: Select all
#include "testMain.h"
#include "newpanel.h"
#include <wx/msgdlg.h>
#include <wx/intl.h>
#include <wx/string.h>
const long testFrame::ID_BUTTON1 = wxNewId();
const long testFrame::ID_BUTTON2 = wxNewId();
const long testFrame::ID_PANEL1 = wxNewId();
BEGIN_EVENT_TABLE(testFrame,wxFrame)
END_EVENT_TABLE()
testFrame::testFrame(wxWindow* parent,wxWindowID id)
{
wxBoxSizer* BoxSizer2;
wxBoxSizer* BoxSizer1;
Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("id"));
BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);
BoxSizer2 = new wxBoxSizer(wxVERTICAL);
btCreate = new wxButton(this, ID_BUTTON1, _("Create"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1"));
BoxSizer2->Add(btCreate, 0, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
btClose = new wxButton(this, ID_BUTTON2, _("Close"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON2"));
BoxSizer2->Add(btClose, 0, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
BoxSizer1->Add(BoxSizer2, 0, wxALL|wxEXPAND|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
BoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
pnMain = new wxPanel(this, ID_PANEL1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL1"));
pnMain->SetBackgroundColour(wxColour(255,255,128));
BoxSizer3->Add(pnMain, 1, wxALL|wxEXPAND|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
BoxSizer1->Add(BoxSizer3, 1, wxALL|wxEXPAND|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
SetSizer(BoxSizer1);
BoxSizer1->Fit(this);
BoxSizer1->SetSizeHints(this);
Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&testFrame::OnbtCreateClick);
Connect(ID_BUTTON2,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&testFrame::OnbtCloseClick);
}
testFrame::~testFrame()
{
}
void testFrame::OnbtCreateClick(wxCommandEvent& event)
{
pnMain->Destroy();
pnMain = (wxPanel*)new NewPanel(this);
}
void testFrame::OnbtCloseClick(wxCommandEvent& event)
{
Close();
}
testMain.h
Code: Select all
#ifndef TESTMAIN_H
#define TESTMAIN_H
#include <wx/sizer.h>
#include <wx/panel.h>
#include <wx/button.h>
#include <wx/frame.h>
class testFrame: public wxFrame
{
public:
testFrame(wxWindow* parent,wxWindowID id = -1);
virtual ~testFrame();
private:
void OnbtCreateClick(wxCommandEvent& event);
void OnbtCloseClick(wxCommandEvent& event);
static const long ID_BUTTON1;
static const long ID_BUTTON2;
static const long ID_PANEL1;
wxPanel* pnMain;
wxButton* btClose;
wxButton* btCreate;
wxBoxSizer* BoxSizer3;
DECLARE_EVENT_TABLE()
};
#endif // TESTMAIN_H
newpanel.cpp
Code: Select all
#include "wx_pch.h"
#include "newpanel.h"
const long NewPanel::ID_STATICTEXT1 = wxNewId();
const long NewPanel::ID_TEXTCTRL1 = wxNewId();
BEGIN_EVENT_TABLE(NewPanel,wxPanel)
END_EVENT_TABLE()
NewPanel::NewPanel(wxWindow* parent,wxWindowID id,const wxPoint& pos,const wxSize& size)
{
wxBoxSizer* BoxSizer1;
Create(parent, id, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("id"));
BoxSizer1 = new wxBoxSizer(wxVERTICAL);
StaticText1 = new wxStaticText(this, ID_STATICTEXT1, _("Label"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT1"));
BoxSizer1->Add(StaticText1, 0, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
TextCtrl1 = new wxTextCtrl(this, ID_TEXTCTRL1, _("Text"), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE, wxDefaultValidator, _T("ID_TEXTCTRL1"));
BoxSizer1->Add(TextCtrl1, 1, wxALL|wxEXPAND|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
SetSizer(BoxSizer1);
BoxSizer1->Fit(this);
BoxSizer1->SetSizeHints(this);
}
NewPanel::~NewPanel()
{
}
newpanel.h
Code: Select all
#ifndef NEWPANEL_H
#define NEWPANEL_H
class NewPanel: public wxPanel
{
public:
NewPanel(wxWindow* parent,wxWindowID id=wxID_ANY,const wxPoint& pos=wxDefaultPosition,const wxSize& size=wxDefaultSize);
virtual ~NewPanel();
wxStaticText* StaticText1;
wxTextCtrl* TextCtrl1;
protected:
static const long ID_STATICTEXT1;
static const long ID_TEXTCTRL1;
private:
DECLARE_EVENT_TABLE()
};
#endif