Inheriting a form within the same project

H

Hemraj Julha

Hi

I'm trying "Visual Inheritance" in C# and facing an issue which might be
related to my ignorance about namespaces and location of the source code
within the folders so I'll try to explain my problem.

I have a windows application called TestApp who's source is located under:

d:\rajooDotNet\C#\TestApp

I create a base form with three buttons and this is saved as
d:\rajooDotNet\C#\TestApp\baseform.vb

The code in this form contains a line at the top as:
namespace TestApp

Now I want to create a new form, say formnew, and inherit the base form. I
follow the instructions in the help, i.e. build the app first and then add
the new Inherted form and using the inheritance browser. I end up with a
source that contains a line like:

public Class formnew : TestApp.baseform
{
// bla bla ....
}

When I want to display the inherited form in the designer I get an error
message stating that the form cannot be displayed and hints things like,
reference the project containing the base form or build the project if it
the base form is in the same project.

I tried and tried until I copied my project to the root folder of the drive
d: i.e my source code is now in

d:\TestApp

I can then successfully view the inherited form in the designer.

So my question is:

How can I use visual inheritance without having my source code at the top
level of the folder and also if I don't want to embed the top level folder,
in my case d:\rajooDotNet\C#, in the namespace?

For your info I had the same problem in VB.NET but this was resolved when I
replaced the line:

code:-----------------------------------------------------------------------
-------
Public Class formnew
Inherits TestApp.baseform

----------------------------------------------------------------------------
--


With


code:-----------------------------------------------------------------------
-------
Public Class formnew
Inherits baseform

----------------------------------------------------------------------------
--



I'm using VS .NET 2002


Thanks for your help.
 
É

Éric Moreau [VB MVP]

In VB.Net, I always have this error if I call subs from the Form_Load (and
some other events) event. This is because these events are executed to draw
the inherited form in the designer.

Maybe you have something like this in C#.

--

HTH

Éric Moreau, MCSD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Concept S2i inc.(www.s2i.com)
 
S

Sijin Joseph

Ok, Firstly you are mixing C# and VB.Net in the same project, i don't think
that is possible. What you need to do is,

1. Create your base form in VB.Net in a seperate project from the one in
which you are creating your inherited form in C#
i.e. BaseForm is One project and Inherited form in another project

2. Add a project reference to the BaseForm project from your C# project.

3. If the BaseForm is in a different namespace than the inherited form then
you need to have a

using BaseNameSpace;

statement in your inhertied form file.


Let me know if you have ny doubts.
 

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