473,385 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

About inheritance when I use window forms

Hello!

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
project."

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
{
}

//Tony
May 12 '06 #1
1 1326
kh
tony

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

kh
May 12 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: KK | last post by:
Windows Forms Inheritance, Incomplete? I was playing around with Windows Forms and found out this Forms Inheritance feature. The moment I saw that, I felt this can be used effectively if the...
2
by: KK | last post by:
** Posting it here cause after couple of days no body responded.** I was playing around with Windows Forms and found out this Forms Inheritance feature. The moment I saw that, I felt this can...
1
by: Jason Hickey | last post by:
Has there been a change in the way the UI designer handles winform inheritance in the 2003 version of visual studio. Consider the following (try it if you are using 2003 Everything seems to work...
15
by: scorpion53061 | last post by:
I am just now really starting to get into inheritance - controls, datasets, views all that stuff and I am seeing the enormous savings in performance and even watching the exe file size go down...
6
by: Bart Schelkens | last post by:
Hi, i've created a base-form from which all the forms in my application need to inherit. This works just fine. I've put some buttons on my base-form. They are displayed correctly, only if my...
1
by: Michael D. Reed | last post by:
I am using the help class to display a simple help file. I generated the help file using Word and saving it as a single page Web page (.mht extension). I show the help file with the following...
0
by: rellik | last post by:
Hi All, I've run into a problem with the MenuStrip control and any help would be greatly appreciated! The problem I've got is that when use a control derived from the MenuStrip class all MDI...
60
by: Shawnk | last post by:
Some Sr. colleges and I have had an on going discussion relative to when and if C# will ever support 'true' multiple inheritance. Relevant to this, I wanted to query the C# community (the...
8
by: Tony Johansson | last post by:
Hello! I wonder can somebody explain when is it suitable to use these methods OnKeyUp, OnKeyDown and OnKeyPress because these raise an event. These are located in class UserControl. If these...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.