starting wxWidgets - wxPanel full size to frame?

This is a discussion on starting wxWidgets - wxPanel full size to frame? within the C++ Programming forums, part of the General Programming Boards category; Heh, I finally got up and running wxWidgets. I'm starting to understand this little by little, but most of the ...

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    85

    starting wxWidgets - wxPanel full size to frame?

    Heh, I finally got up and running wxWidgets. I'm starting to understand this little by little, but most of the stuff is still intriguing. Sizers for example

    Anyway, I've done the tutorial on sizers, and I'm trying to do a wxPanel that covers my whole window (frame?). It should resize when the window resizes. The problem is, I can't figure out how to do it with sizers. The window also has the two buttons in the example. So, I'm trying to keep the buttons in their sizer, with their properties, but in the same time, make the panel in the background be as large (or small) as the window.

    I'm not sure if this is the right forum, but I suppose there are some people around that work with wxWindows.

    Thanka

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    You don't need a sizer for that.

    For a simple program:

    • Make a wxFrame.
    • Add a wxPanel to the frame.
    • Add all GUI components to a sizer.
    • Call SetSizer() on the wxPanel and pass it the sizer.
    • If you'd like to reset the frame to the minimum size needed to fit everything, call SetSizeHints() on the sizer and pass it a pointer to the wxFrame.


    I read somewhere that for wxWidgets, you should always sets a panel on the frame because Windows doesn't do that automatically for you, and things will look kind of odd if you don't.

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    85
    Thanks a ton. Here's the code if anyone interested
    Code:
    DemoFrame::DemoFrame(const wxString& title)
          : wxFrame(NULL, wxID_ANY, title) {
    
        wxPanel *Panel1 = new wxPanel(this, id_panel);
        Panel1->SetFont(wxFont(8, wxSWISS, wxNORMAL, wxNORMAL, false, wxT("Tahoma")));
    
        wxButton *button = new wxButton(Panel1, id_but1, "First");
        wxButton *button2 = new wxButton(Panel1, id_but2, "Don't click Me");
        wxButton *button3 = new wxButton(Panel1, id_but3, "Yay. Last one");
    
        wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
        Panel1->SetSizer(sizer);
    
        sizer->Add(button, 1, wxALIGN_RIGHT);
        sizer->Add(button2, 1, wxALIGN_LEFT);
        sizer->Add(button3, 1, wxALIGN_CENTER);
    
        Panel1->SetSizer(sizer);
        sizer->SetSizeHints(this);
    }
    Of course, you will need to declare the wxWindowIDs.

    *wipes tear from eye*. This is great. I can almost remeber 6 years ago when i was doing something like this in visual basic ^^

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An exercise in optimization
    By Prelude in forum Contests Board
    Replies: 10
    Last Post: 04-29-2005, 03:06 PM
  2. Replies: 11
    Last Post: 03-25-2003, 04:13 PM
  3. Changing a Structures Members array size
    By Xei in forum C++ Programming
    Replies: 1
    Last Post: 11-07-2002, 06:45 PM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  5. File Size and File Size on Disk
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 12-15-2001, 07:03 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21