Click here to Skip to main content
15,921,884 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
I've got a bunch of very similar forms in my windows application, so I'm trying to use one as a master form and inherit from it for the other forms.
So the first form is declared:
public partial class NewItemForm : Form
and subsequent ones as (for example)
public partial class NewDerivedForm : NewItemForm

My program seems to compile and execute just fine, but the VS2010 designer is just going nuts when I try to load the derived forms on the designer surface, showing various errors at various times, most having to do (I believe) with the auto-generated code in the NewDerivedForm.Designer.cs file. Googling led me to "Inheriting Forms Using the Inheritance Picker Dialog Box" in MSDN. The article is relevant to VS2003, however, and I don't think that VS2010 has an Inheritance Picker Dialog Box.

I'm seeing a couple of red flags. Most all of my googled results make mention of this 'inheritance picker' that I can't find, most seem to be quite old, and most of the results are discussing Visual Basic, not C#. And needing an 'inheritance picker' makes me think that this is not as straightforward as I had thought.

So the question: Is what I'm trying to do inherently (pardon the small pun) bad, not the right approach? Is there a trick I'm missing? A better way to approach the problem?

I know some of this is vague, I'm trying to keep it general rather than post a couple of hundred lines of code and error messages. Any insights or guidance are appreciated.
Updated 19-Jan-11 12:36pm

Share this answer
Dell.Simmons 19-Jan-11 18:56pm    
Saw that one and skimmed it. I'll give it another read. Thanks.
VS 2010 has it too. From the Solution Explorer context menu, choose Add New Item, select Inherited Form from the templates, this will take you to the Inheritance Picker dialog.
Share this answer
Dell.Simmons 19-Jan-11 19:36pm    
Oh, there it is. I wasn't drilling deep enough. Thanks
Nish Nishant 19-Jan-11 19:37pm    
You are welcome.
Sergey Alexandrovich Kryukov 19-Jan-11 19:48pm    
A 5. Having a pair of eyes, learn to see.
Rather than inheritance on forms, I usually prefer to create user controls to encapsulate common functionality that can then just be dropped onto each new form that needs it.
Share this answer
Espen Harlinn 20-Jan-11 13:56pm    
5+ Good advice Marcus
Sergey Alexandrovich Kryukov 2-Feb-11 20:17pm    
I would rather agree. My 5.
dojohansen 16-Jan-13 8:09am    
That's fine when what you need fits the control concept. If you want to do form things however, a control doesn't really cut it. (For example, you may want to take control over initial placement and size. Layout too can be a natural form responsibility, even if one could solve the same with some kind of panel control and put the panel with dockstyle 'fill' on every form.)
I was creating my inheriting form by creating a new form
public partial class NewDerivedForm : Form

and then manually going in and changing that to
public partial class NewDerivedForm: NewItemForm

The Monkey See Monkey Do answer to my problem is - Don't do that.

Using the Inheritance Picker template generates a form that does not seem to have the problems with the VS designer that I was experiencing. The auto-generated Designer.cs file created by the template is different from the 'normal' one, and the skeleton code created in the code file is different also. And, no .resx file is created at all.

I'd list the differences between the generated files, but then I'd have to explain them, and that is unfortunately above my current skill level.

Thanks for the help, guys, I really appreciate it.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900