Page 1 of 1

[wxMSW 2.4.2] How to derive correctly from wxPanel

Posted: Mon Jan 10, 2005 11:43 am
by nihil84
Hi to all, I hope this is the right place to post my question. If not can you suggest where it is?

I have some problems with sizers when I try to write my own widgets (i.e.: derived from wxPanel).

Obviously I create end setup all needed sizer inside it and I add itself in a sizer also in the parent window but... nothing works

Where can I find some examples about?
Any help is welcome.

Tanks

Posted: Mon Jan 10, 2005 11:57 am
by wxNewbi
What error are you getting or have you got a code snippet. this could make it easier to understand the problem :D

Posted: Mon Jan 10, 2005 2:04 pm
by nihil84
Sorry. Here some code.

This is the constructor of the class derived from wxPanel:

Code: Select all

MyPanel::MyPanel(wxWindow* parent,wxWindowID id) {
	this->Create(parent,id,wxDefaultPosition,wxSize(300,200));
	
    topsizer = new wxBoxSizer(wxVERTICAL);  // declared as class-member
   SetBackgroundColour(wxColour(254,241,12)); // YELLOW for test

    topsizer->Add(
	new wxTextCtrl( this, -1, "My text.", wxDefaultPosition, wxSize(100,60), wxTE_MULTILINE),
	1,            // make vertically stretchable
	wxEXPAND |    // make horizontally stretchable
	wxALL,        //   and make border all around
	10 );         // set border width to 10


    this->SetSizer(topsizer);
    topsizer->SetSizeHints(this);
}
here how I add the panel in the main frame:

Code: Select all

	mainsizer->Add(new EstimateCtrl(this,-1),1,wxEXPAND,0);

	this->SetSizer(mainsizer);
	mainsizer->SetSizeHints(this);
But if I use the class in this way the panel is resized correcly (I can see the yellow spot became bigger or smaller) but the text control inside not and the border arount it is not displayed. why?

please, help me.

Posted: Mon Jan 10, 2005 2:16 pm
by nihil84
nihil84 wrote: here how I add the panel in the main frame:

Code: Select all

	mainsizer->Add(new EstimateCtrl(this,-1),1,wxEXPAND,0);

	this->SetSizer(mainsizer);
	mainsizer->SetSizeHints(this);
OPS.I make a mistake while reporting. Correct is:

Code: Select all

	mainsizer->Add(new MyPanel(this,-1),1,wxEXPAND,0);