MDI Passing Form to Class Library type from.

B

Brian K. Williams

Maybe this isn't the best way to do this... But this is what I have.

My Solution:
Project1 = Output Type (Windows Application)
FormMain.cs (MDI Parent)
Project2 = Output Type (Class Library)
Form1.cs
Project3 = Output Type (Class Library)
Form2.cs

All projects share the same Namespace (SPAdmin).


What I would have done if Form1.cs was under Project1 would have been.
public Form1(SPAdmin.FormMain passedForm)
{
passedForm.PublicMethod.DoSOmething();

}

When I attempt to do this with a Class Library SPAdmin.FormMain is not
available.

The main resion I wrote this application in this manner as so that I could
easly update one class library without haveing to update the entire app.

Thanks in advance.
Brian K. Williams
 
S

Sijin Joseph

Hi Brian,

There is a problem here, t be able to use SPAdmin.FormMain in Project2
you need to add a reference to Project1 in Project2, but since Project1
also needs a reference to Project2 in order to create Form1 you have a
circular dependency problem.

To break this, what you will have to do is take whatever public methods
you intend to use from FormMain put them in an interface and then have
FormMain implement that interface. Put the interface in a seperate
project. Make Project1 refer to both the interface and Project2,Project3
and the Child form projects only reference the interface project.

Here is how it would look

My Solution:
Project1 = Output Type (Windows Application)
FormMain.cs (MDI Parent)
References - Project(s)2,3,4

Project2 = Output Type (Class Library)
Form1.cs
References - Project4

Project3 = Output Type (Class Library)
Form2.cs
References - Project4

Project 4 = Output Type (Class Library)
IMainForm.cs


All projects share the same Namespace (SPAdmin).
public Form1(SPAdmin.IMainForm passedForm)
{
passedForm.PublicMethod.DoSOmething();

}

IMainForm.cs

public interface IMainForm
{
void DoSomething();
}

public class FormMain : Form, IMainForm
{
public void DoSomething();

public void CreateChildForm()
{
Form1 f1 = new Form1((IMainForm)this);
f1.Show();
}
}


Hope that is clear, let me know if you need further help.

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph
 

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