Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# VS2010 Forms
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.
Posted 19-Jan-11 13:34pm
Edited 19-Jan-11 13:36pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
Dell.Simmons at 19-Jan-11 18:56pm
   
Saw that one and skimmed it. I'll give it another read. Thanks.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Comments
Dell.Simmons at 19-Jan-11 19:36pm
   
Oh, there it is. I wasn't drilling deep enough. Thanks
Nishant Sivakumar at 19-Jan-11 19:37pm
   
You are welcome.
SAKryukov at 19-Jan-11 19:48pm
   
A 5. Having a pair of eyes, learn to see.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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.
  Permalink  
Comments
Espen Harlinn at 20-Jan-11 13:56pm
   
5+ Good advice Marcus
SAKryukov at 2-Feb-11 20:17pm
   
I would rather agree. My 5.
--SA
dojohansen at 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.)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,260


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 19 Jan 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100