I am following a tutorial to learn how to create simple GUIs with C++. (Video from the tutorial series I am using here(https://www.youtube.com/watch?v=_2FMt_0wVMM&list=PLFk1_lkqT8MbVOcwEppCPfjGOGhLvcf9G&index=4).
For this I am using Visual Studio 2022
Here is the code for the mainframe.
#include "MainFrame.h"
#include <wx/wx.h>
MainFrame::MainFrame(const wxString& title) : wxFrame(nullptr, wxID_ANY, title) {
wxPanel* panel = new wxPanel(this);
wxButton* button = new wxButton(this, wxID_ANY, "Button", wxPoint(150, 50), wxSize(100, 35));
wxCheckBox* checkBox = new wxCheckBox(panel, wxID_ANY, "CheckBox", wxPoint(550, 55));
wxStaticText* staticText = new wxStaticText(panel, wxID_ANY, "Static Text - NOT editable", wxPoint(120, 150));
}
The code runs 100% fine, however when my GUI pops up when I run on debug, the GUI only displays the button, but not the text or the checkbox.
Someone please help I’m learning this for a school project and I really want to get on with learning all this.
2
Answers
Easy fix, I switched the wxPanel constructor for this:
And changed the pointer on the wxButton from 'this' to 'panel' and now everything appears as intended. Here is the new code:
Thank you for your help everyone, much appreciated. :)
You need to make the panel bigger in order for the controls you place in it to be seen. You currently use
mxDefaultSize
, which is pretty small, as can be seen in the top left corner of your picture.The constructor you use is:
Example: