Search code examples
c++wxwidgets

How to make a similar interface using wxWidgets?


How to make a similar interface using wxWidgets form ? I need to dynamically create text fields. I know how to do this with Delphi gitHub. But how to do it with C++ and wxWidgets?

here is my code. I do not understand what to do

Simple::Simple(const wxString& title)
: wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(270, 450))
{
    wxBoxSizer *hbox = new wxBoxSizer(wxVERTICAL);

    for (int i = 0; i < 25; i++)
        {
            hbox->Add(new wxListBox(this, wxID_ANY, wxDefaultPosition, wxSize(250, 60)), wxSizerFlags(0).Border(wxALL, 5));
            auto itm = hbox->GetItem(i);
            itm->SetId(i);
        }
    SetSizer(hbox);
}

Solution

  • @Nindzzya,

    Basically you create a wxFrame. You put an instance of wxScrolled<> in it. Then inside this wxScrolled<>() you put a vertical wxBoxSizer. And then finally add the appropriate controls inside that sizer.

    Following your example:

    for (auto i = 0; i < 25; i++)
        {
            textctrl[i] = new wxTextCtrl( this, wxID_ANY, wxDefaultPosition, wxSize( 250, 60 ), wxSizerFlags( 0 ).Border( wxALL, 5 ) )
            hbox->Add( textctrl[i] );
        }
    
    MyFrame::Some_Func()
    {
        for( auto i : { 0, 25 } )
        {
            textctrl[i]->GetValue();
        }
    }
    

    You don't even need an id or anything like this. And this question is about basic C++. It doesn't have anything to do with wxWidgets.