views:

2928

answers:

5

Working with VS.NET 2008, output type Class Library, Target Framework .NET 2.0

I've come up with a simplified scenario to ask this question.

I have a Button user control, its a simple panel with a single big button on it.

I want to create a RedButton control that extends Button, and similarly, a GreenButton.
e.g. Class RedButton : Button

Ideally, when I open up RedButton's designer I will see the button that I created in Button and be able to modify it, for example make it Red, or change font, etc.

I've tried to do this once, but when I open up the RedButton's designer I just get a bunch of errors.

In this case, doing all this work programatically isn't an option for us, as in the real case this would be a pain.

Could someone shed some light on this? Thanks Very Much.

A: 

Is your assembly setup to be delay signed? Look for the delay signing attribute as well as the checkbox in project properties. I've seen delay signing cause this sort of problem with VS2005 perhaps its still a problem in VS2008.

Brian Ensink
A: 

I had to deal with this problem for years at an old company. I researched it a little back then. I don't think that there is a solution for this.

I don't know how much you want to extend the base class in your real example, but the changes you mentioned in your example would be trivial. Just something like

btnTheButton.BackGround=Color.Red;

In reality, probably whatever changes you need to make to button could be done in a few minutes. It is unfortunate that this will be a few minutes everytime you need to inherit a new control, but I think it's the only option

Jacob Adams
+1  A: 

Truthfully, your example should work just fine. Just ensure that you provide a default constructor for your derived class. Also ensure that you do not use generic controls as the designer will have no clue how to create an instance of it.

Brian Rudolph
A: 

If the control you inherit from is from a DLL and not just another class in the solution, then your designer will render the inherited control properly. My guess is that the VS Design View needs the DLL to draw the control. There may be other ways around this as well.

nc
A: 

Since VS.NET 2008 the root designer is able to present "bunch of errors" as you mentioned. In general the described scenario should “just work”.

What kind of errors are you facing?

Chris Richner