Wow. I just tracked down a bug that has been pwning me for some time.

We had some UserControls in our application whose "tab" behaviour was really weird. Some controls you could tab from one to the next without any difficulties, others required two presses of the Tab key. You'd hit Tab once, and focus would seem to disappear, then hitting Tab again would bring focus to the next control.

On top of that, there were one or two UserControls where you could sometimes see a button underneath (and slightly to the left of) another button. Clicking on this "phantom button" had no effect, but it was ugly and needed to be removed.

These UserControls are all inherited from a common ancestor, who in turn inherits from another UserControl, so it was a bit of a pain to debug where these tab problems and phantom buttons were coming from, but I finally worked it out today.

It turns out that we had overloaded the constructor of one of the ancestor UserControls, to do this:

 public GridControlPage(AgentBase a): this() { InitializeComponent(); agent = a; } 

See the problem? Well, it's not immediately obvious until you remember that the default constructor for a UserControl already calls InitializeComponent!!!

So when our UserControl was constructed, it would add all of its controls to itself, then add them all a second time! The fact that certain controls were disabled by default meant that not every control was part of the tab order, and since they were all being placed in exactly the same spot the second time around, they were, for the most part, completely hidden from view.

So anyway ... the moral of the story is to watch for duplicate calls to InitializeComponent. It kind of makes me wish that InitializeComponent was a virtual protected method that was called from System.Windows.Forms.ContainerControl's constructor, so derived forms didn't have to worry about calling it.