I have a Custom control derived from wxControl,inside a dialog with a vertical sizer
wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
Knob* newKnob = new Knob(panel,wxID_ANY,wxDefaultPosition,wxSize(40,40));
topSizer->Add(newKnob,0,wxALL|wxALIGN_CENTER);
panel->SetSizer(topSizer);
topSizer->Fit(panel);
//panel is a wxPanel inside the dialog
But for some reason ,the custom controls’ size is set at (80,100).If i resize the dialog beyond that size its aligned to center as i specified.
EDIT:
Am using wx 2.8.9 on windows Vista with visual studio 2005.
What could be missing?
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:(taken from
src/msw/control.cpp) with the values(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 inwxControl. It is though, because it is introduced inwxWindow:(taken from
include/wx/window.h).wxWindowis a parent class ofwxControl, so the method is indeed virtual and you can of course override it. Many controls do in fact, as agrepin the sources will show you.