Problems with an inherited Form

G

Guest

(Originally posted this in VC++ section .. whoops

I'm working on a series of projects which have a few things in common, which has been abstracted into an object we'll call ParentForm. I started a new (actually, the first) project. It's "main" form is called ChildForm, and it inherets from ParentForm. I added ParentForm.cs to the project via the Solution Explorer. If I right click on ParentForm.cs and choose "View Designer" I can see the designer just fine. The form appears exactly as it should. However, if I do the same for ChildForm.cs, I get this error: "An exception occured while trying to create an instance of <namespace>.ChildForm. The exception was "Object reference not set to an instance of an object." Oddly enough though, I can compile and run ChildForm fine. I just can't design it. Any suggestions

//ParentForm.c
namespace myNamespac

public class ParentForm : System.Windows.Forms.For

//Member variables such as Menu, MenuItems, TextBox, etc

public ParentForm(

InitializeComponent()
...


..

// No Mai



//ChildForm.c

namespace myNamespac

public class ChildForm : ParentFor

//No new members yet as I'm just trying to get the design set up

public ChildForm() : base(

InitializeComponent()
..


..

static void Main(

Application.Run( new ChildForm() )
 
J

John Baro

Where you have the ctor
public ChildForm() : base()
try getting rid of the : base()
I dont think it is needed as the base ctor will execute anyway. No?
I have a couple of inherited forms which follow this rule and they all work
fine.
Cheers
JB
Uty said:
(Originally posted this in VC++ section .. whoops)

I'm working on a series of projects which have a few things in common,
which has been abstracted into an object we'll call ParentForm. I started a
new (actually, the first) project. It's "main" form is called ChildForm,
and it inherets from ParentForm. I added ParentForm.cs to the project via
the Solution Explorer. If I right click on ParentForm.cs and choose "View
Designer" I can see the designer just fine. The form appears exactly as it
should. However, if I do the same for ChildForm.cs, I get this error: "An
exception occured while trying to create an instance of
<namespace>.ChildForm. The exception was "Object reference not set to an
instance of an object." Oddly enough though, I can compile and run
ChildForm fine. I just can't design it. Any suggestions?
 
G

Guest

Thanks for your reply. I have it a try but unfortunatly I still get the same exception when trying to view ChildForm in the IDE's designer.
 
G

Guest

So, I decided to start over from scratch, sort of, by slowly adding my original code to a new project. ParentForm had a series of event handlers which get initialized in a function I called InitializeEventHandlers. I made it a public function. If it is called in ParentForm's constructor, I get the error. If it is called in ChildForm's constructor I do not. So, I found a way around it ... but I would call this a fairly annoying design flaw. Good thing I've got a client paying for this time, right? :mad:
 

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