You didn't provide any information about the wxWidgets version or your platform / compiler, so I will answer for wxWidgets 2.8 and MSW.
The size you specify is not necessarily used for the control, since the best size for different platforms may well be different. Even on Windows the size will usually depend on the default GUI font. So there are various methods in wxWidgets that let windows specify their minimum, best or maximum size. If you have special requirements you may need to override some of them.
For your problem it looks like you want to have the control have a smaller size than the default best size of wxControl
:
wxSize wxControl::DoGetBestSize() const
{
return wxSize(DEFAULT_ITEM_WIDTH, DEFAULT_ITEM_HEIGHT);
}
(taken from src/msw/control.cpp
) with the values
#define DEFAULT_ITEM_WIDTH 100
#define DEFAULT_ITEM_HEIGHT 80
(taken from include/wx/msw/private.h
).
If you override DoGetBestSize()
to return your intended size it should work.
Edit:
You comment that you cannot override DoGetBestSize()
since it is not virtual in wxControl
. It is though, because it is introduced in wxWindow
:
// get the size which best suits the window: for a control, it would be
// the minimal size which doesn't truncate the control, for a panel - the
// same size as it would have after a call to Fit()
virtual wxSize DoGetBestSize() const;
(taken from include/wx/window.h
). wxWindow
is a parent class of wxControl
, so the method is indeed virtual and you can of course override it. Many controls do in fact, as a grep
in the sources will show you.