Hi! True, wxFrame resizes its child window and this is quite correct.If the frame has exactly one child window, not counting the status and toolbar, this child is resized to take the entire frame client area. If two or more windows are present, they should be laid out explicitly either by manually handling wxEVT_SIZE or using sizers The best way to go is by using sizers. "A little workaround I found is to add first a wxPanel to the wxFrame as basis control and to create other controls using this wxPanel as parent." I'd say that this is not just a "workaround", but quite a standard procedure. :) Again I simply quote the docs:
A panel is a window on which controls are placed. It is usually placed within a frame. It contains minimal extra functionality over and above its parent class wxWindow; its main purpose is to be similar in appearance and functionality to a dialog, but with the flexibility of having any window as a parent. So except from situation where you only have one child window that should get resized (like a wxTextCtrl in a wxFrame serving as a editor), you'll use a wxPanel in conection with a wxSizer to layout the controls on this panel.
The following code snippet should display a wxStaticLine in the center of a wxPanel and get resized. MyFrame.h
#include <wx/wx.h>
#include <wx/image.h>
#ifndef MYFRAME_H
#define MYFRAME_H
#include <wx/statline.h>
class MyFrame: public wxFrame {
public:
MyFrame(wxWindow* parent, int id, const wxString& title, const wxPoint& pos=wxDefaultPosition, const wxSize& size=wxDefaultSize, long style=wxDEFAULT_FRAME_STYLE);
protected:
wxStaticLine* staticLine;
wxPanel* panel;
};
#endif MyFrame.cpp
#include "MyFrame.h"
MyFrame::MyFrame(wxWindow* parent, int id, const wxString& title, const wxPoint& pos, const wxSize& size, long style):
wxFrame(parent, id, title, pos, size, wxDEFAULT_FRAME_STYLE)
{
panel = new wxPanel(this, -1);
staticLine = new wxStaticLine(panel, -1);
wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(staticLine, 1, wxALIGN_CENTER_VERTICAL, 0);
panel->SetAutoLayout(true);
panel->SetSizer(sizer);
}
main.cpp
#include <wx/wx.h>
#include <wx/image.h>
#include "MyFrame.h"
class MyApp: public wxApp {
public:
bool OnInit();
};
IMPLEMENT_APP(MyApp)
bool MyApp::OnInit()
{
wxInitAllImageHandlers();
MyFrame* frame = new MyFrame(NULL, -1, "wxFrame");
SetTopWindow(frame);
frame->Show();
return true;
} Hope this helps ;-)upCASE ----------------------------------- If it was hard to write, it should be hard to read!- Do. Or do not. There is no try! |