Inheriting from a UserControl

E

elziko

I would like to do the following:

Create a class that inherits from a usercontrol. Then add a control to the
designer Call this new class ClassA.

Many controls I need will start off like this so I'd like to create all
controls form now on from this base control.

So, for example, I inherit from this base control and add the further
controls required to form this part of my UI. Call this ClassB

However, when I try and drop the final control (ClassB) onto a form none of
the controls added after inheriting from ClassA are visible.

Why is this and is what I'm doing not possible?

The idea behind this is other people can create controls for my application
but by inhriting from ClassB I will force them to give some basic
functionality that I have defined in ClassA. I know I can give them an
interface that they have to implement but this doesnt provide them with all
the code that must also be present. Otherwise I must just give them ClassA
uncompiled and **ask** them not to change any of the code found there.

Is this making any sense?

Cheers,

elziko
 
M

Microsoft

Make sure you access modifiers are set correctly for your class members so
that are available to the inherited class.

Dont forget, constructors are not inherited and need to be called on the
base class.

HTH
 
E

elziko

Thanks youir post got me thinking...

I found that when I add a control to ClassB it creates and populates an
InitializeComponent procedure but fails to add any code to call it! I can't
think of a reason why you'd want to instantiate such a component but not
initialiase it.
 
H

Herfried K. Wagner [MVP]

elziko said:
Create a class that inherits from a usercontrol. Then add
a control to the designer Call this new class ClassA.

Many controls I need will start off like this so I'd like to
create all controls form now on from this base control.

So, for example, I inherit from this base control and
add the further controls required to form this part of
my UI. Call this ClassB

However, when I try and drop the final control (ClassB)
onto a form none of the controls added after inheriting
from ClassA are visible.

I am not able to reproduce that with .NET 1.1. Both, controls added in the
usercontrol's base class and the usercontrol itself are visible when I drag
the final usercontrol onto the form.
 
E

elziko

OK as I reported earlier I can now get all controls to appaer when I drag my
final control on a form.

However, I know have a related problem at runtime. I am actually loading
these componets as plug-ins. When I create an object from the assembly and
try and add it to a container at runtime it is added as my BaseClass not the
class that inherits from it.

If I do a GetType on the object it knows that it is based on ClassB although
the UI only displays the controls from ClassA. Is there any way around this?

TIA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top