Search code examples
wxwidgets

Creating radio button


I am working with radio buttons in wxWidgets and I am having a problem initializing the size of the button and its coordinates on the frame.

The following code creates the radio button, but it does not give it the correct size and starting coordinates (wxPoint and wxSize do not work).

My question is: How do I implement correctly wxSize and wxPoint in this case?

Thanks,

        //Units Radio Box
    wxString choices[] = { "Metric (mm)","Imperial (in.)" };
    int Num_Choices = 2;

wxRadioBox * Units;

    Units = new wxRadioBox(this,
                            wxID_ANY, 
                            _T("Input Units"),
                            wxPoint(-20,-25),
                            wxSize(20,20), 
                            Num_Choices,
                            choices,
                            1,
                            wxRA_SPECIFY_COLS,
                            wxDefaultValidator,
                            _T("Input Units"));

Solution

  • As mentioned in EVT_SIZE description of wxFrame documentation, it resizes its only child to fill the entire client area by default. This is something that is very convenient in the common case when you have a wxPanel as the single child of the frame, but obviously not so much if you want to have just a radio box.

    To fix this, define your own wxEVT_SIZE handler doing nothing. Or, maybe even simpler, just create another window (that could be a wxStaticText without label, making it effectively invisible).

    Of course, using absolute position and sizes is not going to work in any case because of the differences between platforms, displays DPI etc, so it's strongly not recommended to do this. Use sizers for the layout instead of at the very least use dialog units instead of values in pixels.