Visual Inheritance and Generic Forms / Controls Part 2

Visual Inheritance and Generic Forms / Controls Part 2

Old forum URL: forums.lhotka.net/forums/t/80.aspx


xal posted on Friday, May 12, 2006

Hi all!

I've updated my Generic Inheritance Sample to add support for altering the inherited controls.

This means that if your base class contains a button, you'll be able to move it around and change it's properties in the inherited form's designer.

Since this forum lacks file upload capability I posted it in the old forum:
Here's the link

Andrés

Mark replied on Friday, May 12, 2006

Side note - it does look like the forum has upload capability, it's just we don't have permission to upload.  If you click on the "Options" tab when composing a message, there *is* a File Attachment "Add/Update" button.  Just doesn't work (yet).

xal replied on Friday, May 12, 2006

Sorry, for the ones that don't know what the hell I'm talking about:

-This is a sample you can use to create a base form (that may be MustInherit or not) that supports generic types.

This is an operation that is not supported be the vs designer, but with the example I posted you can make the VS 2005 designer support it.

So now you can create a form like :
Public Class MustInherit MyBaseForm(Of T as BusinessBase(Of T))
...
'It can contain things such as:
'Public Property DataSource As T
'Public MustOverride Function DoSomething()

'You can also have all your security handled here, or the common save procedures
'or whatever you think you can reuse....
...
End Class

This is a real time saver, it allows you to take advantage of all the great features in .net 2.0 and have a better oo design in your ui.

Andrés

xal replied on Monday, May 15, 2006

Now that we can post attachments, I decided I might as well do it..!

Andrés

burmajam replied on Tuesday, August 01, 2006

Hi xal

Few months ago I tried this stuff with C# but couldn't make it. Is there somewhere C# example of this usefull techinque?

xal replied on Tuesday, August 01, 2006

Hey!
The project I posted is based on this article:
http://www.urbanpotato.net/Default.aspx/document/2001

The original code was in c# and I ported it to vb. The original code didn't have support for generics and it failed to let you control the inherited controls (you couldn't move them around and change their properties).

It took a lot of time to develop that because I had to do it blindly. Anyway, I currently don't have time to port that to c# but I'd like to.

One thing I'm not sure about is how c# exposes controls in windows forms. In vb, even though they are actually fields, when you reflect upon the controls, you find that a protected button named "button1" is actually a private field named "_button1" and a protected property named "button1".
If the behaviour in c# is the same, you could use the attributes as they are and just reference the dll that contains them (you'd have to make them public though). If it's not, you could still use the attributes, but you just won't be able to drag/resize/alter inherited controls in any way (from the designer). If you really need that (which in 90% of the times I don't) you can just change the fragment of code that uses reflection to get the controls and add them to the design site. It's an event handler in one of the attributes.

You could also use reflector to help you port it to c#.

Andrés

Copyright (c) Marimer LLC