Inheriting usercontrols

Y

YYZ

I swear I've done my research, and now I was just hoping someone could
explain this to me.

I've got a base class (usercontrol) that I am using just as an
interface. Meaning, I've defined several MustOverride subs in there,
and also a public property.

I'm going to inherit a bunch of usercontrols from this one superclass
(terminology correct?) and then they all have to make sure they can
respond to that set of functions that I've defined. Sounds good to me.

However, I keep getting the error of "The designer must create an
instance of type 'EncLO.ucLoanSuper' but it cannot because the type is
declared as abstract.

Right, I've seen the advice of wrapping my super class definition in
#If DEBUG.... However, that defeats the purpose, right? I mean, I can
actually declare my class normally (without the MustInherit) and then
just make Overridable subs instead of MustOverride subs. But that
won't FORCE me to implement all of those subs in all the child
usercontrols. It doesn't do me any good to do this only at runtime,
because by that time it is too late.

Am I making sense? Any other solution that anyone can think of to
force the usercontrols that inherit from my superclass to implement
that set of subs?

Matt
 
G

Guest

Inherited User controls also inherit all of the designer UI elements of the
base class. Therefore, the designer tries to create an instance of the base
control in order to display. As you know, it is not possible to create an
instance of a MustInherit class so the designer gets an error.

Your code will work. But, there is no way to use the designer to visually
edit each derived control. You'll need to add your UI elements into the code
directly. :(
 
G

Guest

Another option would be to create a new class that inherits the
System.Windows.Forms.UserControl class and add your MustInherit methods
there. Then base all of your derived usercontrols from this base class
instead instead of UserControl.
 
Y

YYZ

Another option would be to create a new class that inherits the
System.Windows.Forms.UserControl class and add your MustInherit methods
there. Then base all of your derived usercontrols from this base class
instead instead of UserControl.

Maybe I didn't explain it right, but that's exactly what I did. And
..Net changed the class definition for me behind the scenes to
MustInherit -- only after a compile, or closing and opening the
project...not sure wich.

So again, I know WHY it can't create the instance of the base class
(because it is defined as MustInherit, so it can't be created, only
inherited), but I don't see how this benefits me. I mean, I WANT to
make methods MustOverride so that every control implements them, but
then I can't design in the designer...and adding controls all
non-visually is going to be a huge PITA that i don't want to do.

I just think that they way MS has implemented this type of interface
has really made it unusable. I mean, if I just count on those methods
being there, then there isn't a need to inherit in the first place...

Matt
 

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