To stupid to use sizers

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
Florianx
In need of some credit
In need of some credit
Posts: 1
Joined: Fri Oct 07, 2005 2:33 pm

To stupid to use sizers

Post by Florianx » Fri Oct 07, 2005 2:44 pm

Hi,
I'm trying to use wxBoxSizer since a few hours now, but I don't work...
The Textbox should be fill my hole panel, but it does not resize.
Here my code (constructor of my panel):

Code: Select all

wxBoxSizer *topsizer = new wxBoxSizer(wxVERTICAL);

wxBoxSizer *button_sizer = new wxBoxSizer(wxHORIZONTAL);
button_sizer->Add(new wxButton( this, idCodeButton, "Code" ),
    wxSizerFlags(0).Left().Border(wxALL, 0));
button_sizer->Add(new wxButton( this, idViewButton, "View" ),
    wxSizerFlags(0).Left().Border(wxALL, 0));
topsizer->Add(button_sizer, wxSizerFlags(0).Left().Expand().Border(wxALL, 0));

topsizer->Add(m_CodeControl = new wxTextCtrl( this, idCodeControl,
    "My text.", wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE),
    wxSizerFlags(1).Expand().Left().Border(wxALL, 0));

SetAutoLayout(true);
SetSizer(topsizer);
topsizer->Fit(this);
topsizer->SetSizeHints(this);
Layout();
What have i to do, to let the textbox automatically resize to the fill the hole panel?

Tyler
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 246
Joined: Fri Sep 03, 2004 12:37 am
Contact:

Post by Tyler » Fri Oct 07, 2005 8:19 pm

Hey Florianx,

Well when you're working with the stretch capability of sizers, there's two factors you need to take into account. Those would be the second and third parameters to the Add function.

The second parameter dictates if the control can stretch in the direction of the sizer's orientation. This means if you have a wxBoxSizer that is wxHORIZONTAL, then if you call sizer->Add(control, true...) then this control will stretch horizontally. If you want this control to also be able to stretch in the direction opposite of the sizer's orientation then you need to pass wxEXPAND in the third parameter. So the previous line would be re-written as sizer->Add(control, true, wxEXPAND). This would allow the control to stretch both horizontally and vertically. Here's a simple example:

Code: Select all

wxPanel* content = new wxPanel(this);

wxTextCtrl* text = new wxTextCtrl(content, wxID_ANY, "");
wxButton* ok = new wxButton(content, CMD_OK, "OK");

wxBoxSizer* buttonSizer = new wxBoxSizer(wxHORIZONTAL);
buttonSizer->Add(ok, false);  // don't let the button stretch horizontally the omission of wxEXPAND means it can't stretch vertically either

wxBoxSizer* textSizer = new wxBoxSizer(wxHORIZONTAL);
textSizer->Add(text, true, wxEXPAND);  //let it stretch horizontal and vertical

wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL);
topSizer->Add(buttonSizer, true, wxEXPAND); // let it stretch horizontal and vertical
topSizer->Add(textSizer, false, wxEXPAND); //only let it expand horizontally
content->SetSizer(topSizer);

Hopefully that should be enough to get you started, but I highly highly recommend using DialogBlocks http://www.anthemion.co.uk/dialogblocks/ instead of coding it by hand because it will save you hours.

-Tyler

Post Reply