views:

111

answers:

2

I keep having issues with my code compiling and running fine, yet not loading in the designer. Then I have to debug my visual studio with a second visual studio instance to find the problem. What code is executed by the designer and in what order?

A: 

If you are creating a WinForms application, then it is the code in .designer.cs

Chris Brandsma
+1  A: 

Hmm. I just noticed that when I view my form named 'MainForm' in the designer actually an object of type System.Windows.Forms.Form is created, not of type MainForm. Some of the code in added controls requires that their parent is a MainForm. When executing the code everything was fine but in the designer it wasn't, because no MainForm is created.

This is spot on - I've had the same problem. You need to make sure your child controls can cope with their expected parent not being available. Your form class is available to the control code (so you can call static methods, for instance) but you don't get parented to an instance of it.
RichieHindle