Blog

Home > Blog

Forms, Controls & the Forms Designer

I was just working on a Windows app that contains lots and lots of User Controls all of which inherit from a base User Control.

When I opened the controls they displayed blank in the designer. After some digging I realised that two vital pieces were missing:

  1. All controls need to have a parameterless constructor, but they do not need to be public (mine are “protected”)
  2. The default constructor needs to call InitializeComponent() as this is the method that puts controls into their positions on the form

It seems the Forms Designer creates an instance of the control by calling the parameterless constructor (which seems obvious when you think about it I suppose).

The giveaway on the InitializeComponent() call was the comment just above the call injected by default which reads “Required for Windows Form Designer support“.

Anyways – hopefully this will save somebody some time.


No Comments

Leave a Reply

Level 7, 491 Kent Street, Sydney, Australia  +61 2 9321 1555  info@5limes.com.au
Copyright ©2009 5 Limes Pty Ltd. ABN 87 119 340 680  All Rights Reserved