I want to resize my widget treectrl to fit the panel size
but it bring me so many problem.
it cannot be closed successful,the frame disappear but the programe still remain in memory.I can abide the it,but another problem is annoying,If i wrote
Code: Select all
myTreeCtrl->SetSize(m_panel->GetSize());
I don`t know where is wrong,because I do`nt know the xrc theory.
I think:
the functor LoadFrame will assign resource for all its subwidgets.
May be need LoadPanel If I have a panel.so I need not use the operator "new" for every subwidgets and just like this
Code: Select all
myTreeCtrl=XRCCTRL(*this,"treectrl_1",MyTreeCtrl);
use panel like this
Code: Select all
myTreeCtrl=XRCCTRL(*m_panel,"treectrl_1",MyTreeCtrl);
Please tell me where is wrong,I think the proble may be in MyFrame`s
construct
Code: Select all
#include <wx/wx.h>
#include <wx/treectrl.h>
#include <wx/xrc/xmlres.h>
class MyApp : public wxApp
{
public:
virtual bool OnInit();
};
class MyTreeCtrl :public wxTreeCtrl
{
public:
MyTreeCtrl(wxWindow *parent):wxTreeCtrl(parent)
{
}
};
class MyFrame : public wxFrame
{
public:
MyFrame(wxWindow* parent);
void OnSize(wxSizeEvent& event);
void Resize();
private:
wxPanel *m_panel;
MyTreeCtrl* myTreeCtrl;
DECLARE_EVENT_TABLE()
};
IMPLEMENT_APP(MyApp)
bool MyApp::OnInit()
{
wxXmlResource::Get()->InitAllHandlers();
wxXmlResource::Get()->Load(wxT("1.xrc"));
MyFrame *frame = new MyFrame(wxT(NULL));
frame->Show(true);
return true;
}
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_SIZE(MyFrame::OnSize)
END_EVENT_TABLE()
MyFrame::MyFrame(wxWindow* parent):wxFrame(parent,-1,"hello")
{
wxXmlResource::Get()->LoadFrame(this,parent, wxT("frame_1"));
m_panel=wxXmlResource::Get()->LoadPanel(parent, wxT("panel_1"));
myTreeCtrl=XRCCTRL(*this,"treectrl_1",MyTreeCtrl);
wxTreeItemId rootID = myTreeCtrl->AddRoot(wxT("Root"),-1,-1,NULL);
}
void MyFrame::OnSize(wxSizeEvent& event)
{
Resize();
event.Skip();
}
void MyFrame::Resize()
{
if(myTreeCtrl&&m_panel)
{
myTreeCtrl->SetSize(m_panel->GetSize());
}
}
Code: Select all
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- generated by wxGlade 0.4 on Sun Feb 26 13:17:04 2006 -->
<resource version="2.3.0.1">
<object class="wxFrame" name="frame_1" subclass="MyFrame">
<style>wxDEFAULT_FRAME_STYLE</style>
<title>frame_1</title>
<object class="wxBoxSizer">
<orient>wxVERTICAL</orient>
<object class="sizeritem">
<option>1</option>
<flag>wxEXPAND</flag>
<object class="wxPanel" name="panel_1">
<style>wxTAB_TRAVERSAL</style>
<flag>wxEXPAND</flag>
<flag>wxADJUST_MINSIZE</flag>
<object class="wxTreeCtrl" name="treectrl_1">
<label>asdsdfhfghfgh</label>
</object>
</object>
</object>
</object>
</object>
</resource>
Code: Select all