Guidance Forums / wxWidgets (wxWindows) in C++ / Resizing of child windows

Search 搜索
Home Home

Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Resizing of child windows
Posted by: Michael12 2004-09-01 17:37:27

I have a little problem. May be somebody can help me.

I have class wxApp. It's a main class. Inside of wxApp I declared class wxFrame- it's a frame of my window. Frame has child - wxWindow. You know frame should have window. On this window I situated static line, which is child to window. Okay. Now problem. When I try resize frame, window resize automatically. But I can't resize static line. I tried to use EVT_SIZE, but it doesn't make any result.

If I try use SetSize in wxFrame, it makes an system error. I tried SendEventSize. But it does nothing.

If somebody knows what I can do or, it will be better, has sources, please, answer me or send sources on e-mail:

Thanks beforehand.
Message2. Re: Resizing of child windows
Posted by: 2004-09-01 20:05:27
Try to use wxSizer's. I've noticed, that the wxFrame resizes its child controls automatically to the full size, so you can't then resize the child controls independetly. Perhaps the window style of wxFrame is guilt, I don't know, I'm a newbe in wxWindows too :)) 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. But this is not a nice solution. Try the sizers.
Message3. Re: Resizing of child windows
Posted by: upCASE 2004-09-01 22:03:27
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.

#include <wx/wx.h>
#include <wx/image.h>

#ifndef MYFRAME_H
#define MYFRAME_H

#include <wx/statline.h>

class MyFrame: public wxFrame {
    MyFrame(wxWindow* parent, int id, const wxString& title, const wxPoint& pos=wxDefaultPosition, const wxSize& size=wxDefaultSize, long style=wxDEFAULT_FRAME_STYLE);
    wxStaticLine* staticLine;
    wxPanel* panel;
#endif // MYFRAME_H


#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);


#include <wx/wx.h>
#include <wx/image.h>
#include "MyFrame.h"

class MyApp: public wxApp {
    bool OnInit();


bool MyApp::OnInit()
    MyFrame* frame = new MyFrame(NULL, -1, "wxFrame");
    return true;
Hope this helps ;-)
If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
© Tue 2024-7-23  Guidance Laboratory Inc. Hits:0