Thursday, February 03, 2005

Disappearing WinForms Controls in VS.NET 2003

So, Microsoft has confirmed that there actually is an issue of controls disappearing on the VS.NET 2003 WinForms designer. Tell me something I didn't know yet!

In our current C# project, we used to have constant problems with WinForms designer destroying control code, although the symptoms seem slightly different from those described on MSDN resp. by Shawn Burke. The designer-generated code (in Form.InitializeComponent()) of the affected control was still there, just the ContainerControl.Controls.Add() command on the control's parent had been killed by the designer.

We somehow figured out this had to do with the order in which the controls were declared and created. Again, it's the designer that breeds this code. Now we solved this issue by manually rearranging the order of control declarations and instantiations (parent-control MUST ALWAYS GO BEFORE child-control), and adding the missing Add() command at the end - this way the designer stopped corrupting our forms.

I guess this might be the case once the parent-control is added to the form AFTER the child-control, and when the child-control is then being dragged into the parent-control. Still it only happens under certain conditions.

And another thing: complex forms take years to open in the designer view. Our record form: three minutes and counting (and we do have fast developer machines). We only dare to open it once we REALLY REALLY mean to work on it for a while.

I think it's about time for VS.NET 2003 Service Pack 1. As of today, I would have to contact Microsoft in order to obtain a hotfix.