Sunday, February 7, 2010

.NET SplitContainer panels do not deserve a name?

For some time now I've been coding for a world-wide company called Zehnder. I'm implementing some logistic solutions for their Polish office workers. Technology limits: .NET 2.0.

Some part of the work includes UI - that is, Windows Forms. In order to split the form into two spaces, it seems obvious to use SplitContainer control especially designed for that purpose. Everything seems fine if one does not write unit tests for the UI. When it comes to doing so, a small shortcoming becomes visible - neither of the panels of the split container have a name! Unfortunately, the assumption of NUnitForms is that each control or form has it's own name; that is, one has to make sure that each control has a name. That is not a problem to name a control; it's a matter of simple assignments:

this.SplitContainer1.Panel1.Name = "Panel1";
this.SplitContainer1.Panel2.Name = "Panel2";
 
Not a big deal. But hey, where should one put that code? Is it the InitializeComponents() method body, which is strictly forbidden to be modified manually, a good place for that? Maybe. Until the Designer decides to overwrite this code. All in all, it seems that adding a separate method, let's say - InitializeSplitContainerNames() - and calling it after the InitializeComponents() method (in the form/control constructor) is the best solution (with all of the drawbacks this solution has).

I think.