Can you use abstract UserControls
I created a UserControl called Dad. Marked it as abstract. I created a class Son and changed it to:
public class Son : Dad
{
public Son() : base()
}
If I 'View Designer' on Son it fails with a message saying ...
The Designer must create an instance of type 'Windows.Application1.Dad' but it cannot as the type is declared as abstract.
Is this just a weakness in the IDE

Deriving from abstract UserControls
Damien Watkins - MSFT
Thank you all gentlemen for your replies. The Urban Potato shows this was not such a trivial question. My prime reason for wanting this was to enforce a series of abstract methods on derived UserControls. I decided on a kludge as I did not really understand the UP answer.
I created three classes
public
partial class Dad : UserControl {public Dad() { }}} public abstract class DadAbstract : Dad{
public abstract void MustImplement(); } class Son : DadAbstract { public override void MustImplement() {} public Son() : base( ){ InitializeComponent( ); } ... all control stuff ...}.
DadAbstract contains abstract void MustImplement();
Son contains public override void MustImplement() { /* code */ }
Even though Son does not compile because of the override I can still 'View Designer' and add controls. I then leave the designer and change 'class Son : Dad' to 'class Son : DadAbstract'. This action is (luckily) enforced as it is needed to make Son compile.
Everything then works as the problem is in the IDE rather than .Net. If I need to change the Son controls then all I have to do is change Son back to derive from Dad rather than DadAbstract, do my designer changes then return to Son : DadAbstract.
If you disagree (particularly with the italicised portion) then please put me straight.
tyther
You are able to work around this in Visual Studio 2005, however, it is a little work.
Brian Pepin has blogged on this: http://www.urbanpotato.net/Default.aspx/document/2001.
Anagoge
Alone64179
Mecheniq
Jonas1980
I have done that now.
<excuse>
I am fairly new here and from a powerbuilder background. The PB inheritance model and the code 'compartmentalisation' are easier to understand there - although that leads to less flexibility. The .Net classes are huge, entirely flexible but that leads to a large learning curve. (possibly kerb or curb are more appropriate)
Thank heavens for Intellisense and 'background compile as you code'
</excuse>
...and thanks for the replies
Cesar Burbano
CatalinB
I wanted to enforce the requirements. The Virtual and Interface methods both depend on the derived class 'noticing' they have to implement the inteface or override the methods.
I am relatively new to C# and was trying to find some other way. It takes a long time when you don't really understand what you are doing.
I tried to find a [Designtime] attribute so the IDE would see it as concrete but it would be abstract at run time. No joy.
Maybe (I thought) I can add an Interface to the superclass and somhow say that it need only be implemented by derived classes - couldn't find that one either.
Thanks for your reply - Paul Cotter
Julien Chable
public partial class Dad<T> : UserControl
{
public Dad() { }
}
public abstract class DadAbstract : Dad<string>
{
public abstract void MustImplement();
}
public partial class Son : Dad<string>
{
public Son()
{
InitializeComponent();
}
/*
public override void MustImplement()
{
return;
}*/
}
Peter Zwickl
Hi David,
I was aware of this workaround but presumed that VS.Net 2003 is being used.
Rickard Magnusson
We have two points to contend with-
a/We dont want to use abstract controls since we cant design them.So,we need a non-abstract class with virtual methods to enable overriding.
b/to enforce overriding,throw a custom exception in each of the virtual methods saying that this method needs to be overriden.Will this suit your scenario
guyinkalamazoo