By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,467 Members | 1,448 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,467 IT Pros & Developers. It's quick & easy.

About inheritance when I use window forms

P: n/a

Assume I have three window forms called Frm1, Frm2 and Frm3 each of these
have a method called foo1 and foo2.

Now instead of having this foo1 and foo2 in each of the three window forms I
want to put these foo1 and foo2 in the Base class and then
inherit from this class.

I did the following:
Create a class called Top where I put method foo1 and foo2 then inerit from
Top see below.

When I do this and then try to use forms designer for window form Frm1 I get
into trouble.
I get this error "An error occurred while loading the document. Fix the
error, and then try loading the document again.
The error message follows: The designer could not be shown for this file
because none of the classes within it
can be designed. The designer inspected classes in the file: Frm1 --- The
base class 'Top' could not be loaded.
Ensure the assembly has been referenced or built if it is part of the

So a questiuon is must all window form inherit directly from the Form class?

So if all window form must inherit directly from the Form class how do I
solve my problem
where I want to put some methods in the Base class?

Is the solution that I must keep each method in each window form perhaps as
I had from the beginning.
public class Top : System.Windows.Forms.Form
public void foo1()

public void foo2()
{ }
public class Frm1 : Top

May 12 '06 #1
Share this Question
Share on Google+
1 Reply

P: n/a

your design is a correct in OO terms and should work at runtime, but for
"visual inheritance" to work at design time you need the usual
InitializeComponent calls. i suggest you create your base form with the
designer first.

"viusal inheritance" is all about achieving a common look for your forms. if
you just want common functionality then try implementing in another way (e.g.
a helper class).

May 12 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.