All forms need a constructor which normally calls
InitializeComponent
- and when you create a form in the VS designer by adding a form to your project the defautl constructor is created and does exactly that.
If you don't have one - and your code doesn't show one - then MainForm will work in the designer to add buttons and so forth, as it uses the method itself from the .designer.cs file working to "draw" the controls on screen for you to edit.
So start by checking if you have a MainForm.designer.cs file, and if it contains the
InitializeComponent
method, If it does, you can just recreate your default constructor:
public MainForm() => InitializeComponent();
Will do.