Reputation: 8694
I am undergoing a number of tutorials on wxWidgets and found that I must add a wxPanel
to my main frame in order to get a Windows native-like background, instead of the ugly dark-grey that it defaults to.
Now, the WxSmith tutorial: Hello world states that a wxBoxSizer
is the first control that should be added to the main frame. Then goes the wxPanel
, and then another sizer where I'll put my controls (text, buttons, etc).
I'm failing to understand the need for the first sizer. For me it would make more sense to have the following hierarchy: Frame -> Panel -> Sizer -> Controls.
So, do I really need to add a top-level sizer to my frame, before the panel?
Note: The only purpose of the wxPanel
is to give my window a light-grey background.
Edit In fact, I only get what I want (light background color for the entire window) if the panel is the frame's first and only child control.
Upvotes: 1
Views: 398
Reputation: 22688
No, you don't need a sizer for the panel because wxFrame
automatically resizes its only child to fill its entire client area, just because it's such a common case.
The purpose of wxPanel
is not only to give you the "correct" background, but also to provide correct keyboard navigation among your controls. And the reason it is decoupled from wxFrame
is that some frames don't contain controls but are used as e.g. canvases, in which case the panel would be unnecessary.
Finally, don't be confused: sizers are not controls, they are associated with a window and, in turn, contain (some of) the window children, but are not controls themselves.
Upvotes: 3