woensdag 7 januari 2009

Visual designer Inheritance

I've got quite a few problems with the visual designer (WinForms) in Visual Studio. First of all there is the limitation that forms/user controls cannot be inherited & edited when using Generics. The workaround of making a subclass of that form/usercontrol without generics and inherite again from it works fine.

My abstract form with generics:

public abstract partial class UO_Lijst<T> : UserControl where T: BusinessObject, new()

Directly deriving from it like this:

public partial class UO_User : UO_Lijst<User>

has the problem that it cannot be visual edited. A workaround is to put (in a seperate file) the next code:

public class __UO_User : UO_Lijst<User> {}

After that you can derive from this class and you can edit visually.

public partial class UO_User : UO_Lijst<__UO_User>


 

Secondly the inheritance of forms is only used at the time of creating the inherited form. Changes that are made later on in the parent aren't automatically put in the descendents. This can be a problem that only exists in case of the workaround described above. The workaround for this is after the InitializeComponent() call the base.InitializeComponent(), open the design mode. The visual is changed an the base.InitializeComponent() can be removed.

Geen opmerkingen: