Wednesday, September 21, 2005

Tip #102 - DesignMode only works after a Component is sited

I could almost kick myself... the designer has been busted for months, and I never twigged to this.. I guess it was just easier to code my forms by hand...

The reason for this is simple, someone I used to work with decided all our controls needed to have consistent fonts and colours, without having to change the system settings (Gotta love UI standards). To achieve this, the customisation code as put inside control constructors. This broke all the designers.. I figured it would be an easy fix, just wrap all the customisation code in a check for DesignMode. After this fix didn't work, I just decided I didn't really need the designer anyway.

It turns out, the problem is that the DesignMode property on the Component class is simply a wrapper around the site.DesignMode property. Without the site set, it will always return false. Obviously, a control is not sited until AFTER it's been constructed...

Moving all of the code into the a different location, and suddenly we have the designer back.. yay...

No comments: