Windows Form inheritance problem

S

Steven

Hi Everyone,

I have a problem when I tried to inherit a form from a base form.

I did as follows:

1. Created a based form with 2 private controls and one protected
control. BasedForm is inherited from Windows.Forms.

2. Build the solution

3. Create a derived form by using "Add inherited form..." wizard
from Visual studio. After I clicked OK, Visual studio reported
following errors.

"An error occurred while loading the documnet. Fix the erroe, and then
loading the document again. The error message follows:
The designer could not be shown for tghe file because none of the
classes within it can be designed. The designer inspected the
following classes in the file:
Form1-- The base class 'basedForm' could not be loaded. Ensure the
assembly has been referenced or build if it is part of the project."

All of my code in one project.
Does anyone have idea on how this happens and how to fix, please let
me know.
Thnaks in advance.

Steven
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi Steven,

I am not sure what is the reason of the error in your case, but, in general,
the IDE is known to sometimes behave inconsistently when the visual
inheritance is used. I believe it would be much easier to inherit the form
manually by editing the form class' code.
 
S

Steven

Hi Dmitrity,
I am a beginer to C#. Can you tell me how to "inherit the form
manually by editing the form class' code" and show inherited form in
designer window.
Thanks,

Steven

Dmitriy Lapshin said:
Hi Steven,

I am not sure what is the reason of the error in your case, but, in general,
the IDE is known to sometimes behave inconsistently when the visual
inheritance is used. I believe it would be much easier to inherit the form
manually by editing the form class' code.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Steven said:
Hi Everyone,

I have a problem when I tried to inherit a form from a base form.

I did as follows:

1. Created a based form with 2 private controls and one protected
control. BasedForm is inherited from Windows.Forms.

2. Build the solution

3. Create a derived form by using "Add inherited form..." wizard
from Visual studio. After I clicked OK, Visual studio reported
following errors.

"An error occurred while loading the documnet. Fix the erroe, and then
loading the document again. The error message follows:
The designer could not be shown for tghe file because none of the
classes within it can be designed. The designer inspected the
following classes in the file:
Form1-- The base class 'basedForm' could not be loaded. Ensure the
assembly has been referenced or build if it is part of the project."

All of my code in one project.
Does anyone have idea on how this happens and how to fix, please let
me know.
Thnaks in advance.

Steven
 
D

Dmitriy Lapshin [C# / .NET MVP]

Steven,

In the simpliest case, right-click on the form in Solution Explorer, choose
"View code", then change the following line:

public class Form1: System.Windows.Form

to something like:

public class Form1: MyCoolNamespace.BasedForm.

You might also need to call the base form's constructor, but I am not sure
here - it was several months ago when I did manual form inheritance last
time so I might have forgotten certain details.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Steven said:
Hi Dmitrity,
I am a beginer to C#. Can you tell me how to "inherit the form
manually by editing the form class' code" and show inherited form in
designer window.
Thanks,

Steven

"Dmitriy Lapshin [C# / .NET MVP]" <[email protected]> wrote
in message news: said:
Hi Steven,

I am not sure what is the reason of the error in your case, but, in general,
the IDE is known to sometimes behave inconsistently when the visual
inheritance is used. I believe it would be much easier to inherit the form
manually by editing the form class' code.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Steven said:
Hi Everyone,

I have a problem when I tried to inherit a form from a base form.

I did as follows:

1. Created a based form with 2 private controls and one protected
control. BasedForm is inherited from Windows.Forms.

2. Build the solution

3. Create a derived form by using "Add inherited form..." wizard
from Visual studio. After I clicked OK, Visual studio reported
following errors.

"An error occurred while loading the documnet. Fix the erroe, and then
loading the document again. The error message follows:
The designer could not be shown for tghe file because none of the
classes within it can be designed. The designer inspected the
following classes in the file:
Form1-- The base class 'basedForm' could not be loaded. Ensure the
assembly has been referenced or build if it is part of the project."

All of my code in one project.
Does anyone have idea on how this happens and how to fix, please let
me know.
Thnaks in advance.

Steven
 
S

Steven

Hi Dmitriy,

Thank you for the advice. My question right now is how can I add
some other controls to a derived form visually. I have a problem to do
this because I can not load the derived form to disgner window. I
think I can add them through coding, but that seems to be a big trade
off for the benefit from form-inheritance. Isn't it?

At this point, compare C# with VC++, there is a resource template in
VC++, we can copy/paste to do the similar thing in VC++. Is there
something similar in C#?

By the way, how can I get you reply quickly? it takes some of time
to find your answer from the list.

Steven

Dmitriy Lapshin said:
Steven,

In the simpliest case, right-click on the form in Solution Explorer, choose
"View code", then change the following line:

public class Form1: System.Windows.Form

to something like:

public class Form1: MyCoolNamespace.BasedForm.

You might also need to call the base form's constructor, but I am not sure
here - it was several months ago when I did manual form inheritance last
time so I might have forgotten certain details.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Steven said:
Hi Dmitrity,
I am a beginer to C#. Can you tell me how to "inherit the form
manually by editing the form class' code" and show inherited form in
designer window.
Thanks,

Steven

"Dmitriy Lapshin [C# / .NET MVP]" <[email protected]> wrote
in message news: said:
Hi Steven,

I am not sure what is the reason of the error in your case, but, in general,
the IDE is known to sometimes behave inconsistently when the visual
inheritance is used. I believe it would be much easier to inherit the form
manually by editing the form class' code.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Hi Everyone,

I have a problem when I tried to inherit a form from a base form.

I did as follows:

1. Created a based form with 2 private controls and one protected
control. BasedForm is inherited from Windows.Forms.

2. Build the solution

3. Create a derived form by using "Add inherited form..." wizard
from Visual studio. After I clicked OK, Visual studio reported
following errors.

"An error occurred while loading the documnet. Fix the erroe, and then
loading the document again. The error message follows:
The designer could not be shown for tghe file because none of the
classes within it can be designed. The designer inspected the
following classes in the file:
Form1-- The base class 'basedForm' could not be loaded. Ensure the
assembly has been referenced or build if it is part of the project."

All of my code in one project.
Does anyone have idea on how this happens and how to fix, please let
me know.
Thnaks in advance.

Steven
 
D

Dmitriy Lapshin [C# / .NET MVP]

Thank you for the advice. My question right now is how can I add
some other controls to a derived form visually. I have a problem to do
this because I can not load the derived form to disgner window.

Is this also the case when you have done the manual inheritance through
changing the form class' code?
If this the case, the reason why you can't open the form in the designer is
most likely that the base form's constructor or the inherited form
constructor throws an exception.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Steven said:
Hi Dmitriy,

Thank you for the advice. My question right now is how can I add
some other controls to a derived form visually. I have a problem to do
this because I can not load the derived form to disgner window. I
think I can add them through coding, but that seems to be a big trade
off for the benefit from form-inheritance. Isn't it?

At this point, compare C# with VC++, there is a resource template in
VC++, we can copy/paste to do the similar thing in VC++. Is there
something similar in C#?

By the way, how can I get you reply quickly? it takes some of time
to find your answer from the list.

Steven

"Dmitriy Lapshin [C# / .NET MVP]" <[email protected]> wrote
in message news: said:
Steven,

In the simpliest case, right-click on the form in Solution Explorer, choose
"View code", then change the following line:

public class Form1: System.Windows.Form

to something like:

public class Form1: MyCoolNamespace.BasedForm.

You might also need to call the base form's constructor, but I am not sure
here - it was several months ago when I did manual form inheritance last
time so I might have forgotten certain details.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Steven said:
Hi Dmitrity,
I am a beginer to C#. Can you tell me how to "inherit the form
manually by editing the form class' code" and show inherited form in
designer window.
Thanks,

Steven

"Dmitriy Lapshin [C# / .NET MVP]" <[email protected]>
wrote
in message news: said:
Hi Steven,

I am not sure what is the reason of the error in your case, but, in general,
the IDE is known to sometimes behave inconsistently when the visual
inheritance is used. I believe it would be much easier to inherit
the
form
manually by editing the form class' code.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Hi Everyone,

I have a problem when I tried to inherit a form from a base form.

I did as follows:

1. Created a based form with 2 private controls and one protected
control. BasedForm is inherited from Windows.Forms.

2. Build the solution

3. Create a derived form by using "Add inherited form..." wizard
from Visual studio. After I clicked OK, Visual studio reported
following errors.

"An error occurred while loading the documnet. Fix the erroe, and then
loading the document again. The error message follows:
The designer could not be shown for tghe file because none of the
classes within it can be designed. The designer inspected the
following classes in the file:
Form1-- The base class 'basedForm' could not be loaded. Ensure the
assembly has been referenced or build if it is part of the project."

All of my code in one project.
Does anyone have idea on how this happens and how to fix, please let
me know.
Thnaks in advance.

Steven
 
S

Steven

Dmitriy,
When I used form inheritance, the code of derived form has been
generated. Only the form can not be displayed in the designer window.
so, I could not add the other controls in the derived form. Is there
any other way to add controls to this form?

Steven

Dmitriy Lapshin said:
Thank you for the advice. My question right now is how can I add
some other controls to a derived form visually. I have a problem to do
this because I can not load the derived form to disgner window.

Is this also the case when you have done the manual inheritance through
changing the form class' code?
If this the case, the reason why you can't open the form in the designer is
most likely that the base form's constructor or the inherited form
constructor throws an exception.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Steven said:
Hi Dmitriy,

Thank you for the advice. My question right now is how can I add
some other controls to a derived form visually. I have a problem to do
this because I can not load the derived form to disgner window. I
think I can add them through coding, but that seems to be a big trade
off for the benefit from form-inheritance. Isn't it?

At this point, compare C# with VC++, there is a resource template in
VC++, we can copy/paste to do the similar thing in VC++. Is there
something similar in C#?

By the way, how can I get you reply quickly? it takes some of time
to find your answer from the list.

Steven

"Dmitriy Lapshin [C# / .NET MVP]" <[email protected]> wrote
in message news: said:
Steven,

In the simpliest case, right-click on the form in Solution Explorer, choose
"View code", then change the following line:

public class Form1: System.Windows.Form

to something like:

public class Form1: MyCoolNamespace.BasedForm.

You might also need to call the base form's constructor, but I am not sure
here - it was several months ago when I did manual form inheritance last
time so I might have forgotten certain details.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Hi Dmitrity,
I am a beginer to C#. Can you tell me how to "inherit the form
manually by editing the form class' code" and show inherited form in
designer window.
Thanks,

Steven

"Dmitriy Lapshin [C# / .NET MVP]" <[email protected]>
wrote
in message news: said:
Hi Steven,

I am not sure what is the reason of the error in your case, but, in general,
the IDE is known to sometimes behave inconsistently when the visual
inheritance is used. I believe it would be much easier to inherit
the
form
manually by editing the form class' code.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Hi Everyone,

I have a problem when I tried to inherit a form from a base form.

I did as follows:

1. Created a based form with 2 private controls and one protected
control. BasedForm is inherited from Windows.Forms.

2. Build the solution

3. Create a derived form by using "Add inherited form..." wizard
from Visual studio. After I clicked OK, Visual studio reported
following errors.

"An error occurred while loading the documnet. Fix the erroe, and then
loading the document again. The error message follows:
The designer could not be shown for tghe file because none of the
classes within it can be designed. The designer inspected the
following classes in the file:
Form1-- The base class 'basedForm' could not be loaded. Ensure the
assembly has been referenced or build if it is part of the project."

All of my code in one project.
Does anyone have idea on how this happens and how to fix, please let
me know.
Thnaks in advance.

Steven
 
D

Dmitriy Lapshin [C# / .NET MVP]

Yes, you can create instances of buttons, text boxes and so on
programmatically within the form's constructor after calling
InitializeComponent, configure the controls' properties and then add them to
the form's Controls collection.

Here's an MSDN article on this:

http://msdn.microsoft.com/library/d...n-us/vbcon/html/vbtskaddingcontrolstoform.asp

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Steven said:
Dmitriy,
When I used form inheritance, the code of derived form has been
generated. Only the form can not be displayed in the designer window.
so, I could not add the other controls in the derived form. Is there
any other way to add controls to this form?

Steven

Thank you for the advice. My question right now is how can I add
some other controls to a derived form visually. I have a problem to do
this because I can not load the derived form to disgner window.

Is this also the case when you have done the manual inheritance through
changing the form class' code?
If this the case, the reason why you can't open the form in the designer is
most likely that the base form's constructor or the inherited form
constructor throws an exception.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Steven said:
Hi Dmitriy,

Thank you for the advice. My question right now is how can I add
some other controls to a derived form visually. I have a problem to do
this because I can not load the derived form to disgner window. I
think I can add them through coding, but that seems to be a big trade
off for the benefit from form-inheritance. Isn't it?

At this point, compare C# with VC++, there is a resource template in
VC++, we can copy/paste to do the similar thing in VC++. Is there
something similar in C#?

By the way, how can I get you reply quickly? it takes some of time
to find your answer from the list.

Steven

"Dmitriy Lapshin [C# / .NET MVP]" <[email protected]>
wrote
in message news: said:
Steven,

In the simpliest case, right-click on the form in Solution Explorer, choose
"View code", then change the following line:

public class Form1: System.Windows.Form

to something like:

public class Form1: MyCoolNamespace.BasedForm.

You might also need to call the base form's constructor, but I am
not
sure
here - it was several months ago when I did manual form inheritance last
time so I might have forgotten certain details.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Hi Dmitrity,
I am a beginer to C#. Can you tell me how to "inherit the form
manually by editing the form class' code" and show inherited form in
designer window.
Thanks,

Steven

"Dmitriy Lapshin [C# / .NET MVP]"
wrote
in message news: said:
Hi Steven,

I am not sure what is the reason of the error in your case, but,
in
general,
the IDE is known to sometimes behave inconsistently when the visual
inheritance is used. I believe it would be much easier to
inherit
the
form
manually by editing the form class' code.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Hi Everyone,

I have a problem when I tried to inherit a form from a base form.

I did as follows:

1. Created a based form with 2 private controls and one protected
control. BasedForm is inherited from Windows.Forms.

2. Build the solution

3. Create a derived form by using "Add inherited form..." wizard
from Visual studio. After I clicked OK, Visual studio reported
following errors.

"An error occurred while loading the documnet. Fix the erroe,
and
then
loading the document again. The error message follows:
The designer could not be shown for tghe file because none of the
classes within it can be designed. The designer inspected the
following classes in the file:
Form1-- The base class 'basedForm' could not be loaded.
Ensure
the
assembly has been referenced or build if it is part of the project."

All of my code in one project.
Does anyone have idea on how this happens and how to fix,
please
let
me know.
Thnaks in advance.

Steven
[/QUOTE]
 

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