Neet33
Neet33

Reputation: 281

Dynamicly add controls to wxWidgets dialog

Dialog::Dialog(const wxString & title): wxDialog(NULL, -1, title, wxDefaultPosition, wxSize(200, 200))
{

  panel = new wxPanel(this, -1);

  wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
  wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);

  wxButton *ab = new wxButton(this, wxID_OK, wxT("a"),
      wxDefaultPosition, wxSize(70, 30));
  wxButton *bb = new wxButton(this, wxID_CANCEL, wxT("b"),
      wxDefaultPosition, wxSize(70, 30));

  hbox->Add(ab, 1);
  hbox->Add(bb,1);

  vbox->Add(panel, 1);
  vbox->Add(hbox, 0, wxALIGN_CENTER | wxTOP | wxBOTTOM, 10);

  SetSizer(vbox);

  Centre();
  ShowModal();

  Destroy();
}

Hi, I want to dynamically on button click add wxStaticText in this wxDialog so each time a button is clicked wxStaticText will be added in different location, How can I do that? Thanks for your help.

Upvotes: 1

Views: 1154

Answers (1)

VZ.
VZ.

Reputation: 22753

If you add or remove controls to a window, you need to re-layout it using either wxSizer::Layout() or wxWindow::Layout() which forwards to the former for the window sizer.

Upvotes: 1

Related Questions