Can forms in different projects reference one another?

M

MikeB

Me again. Is it possible to have two projects in a solution (ProjA and
ProjB) and have Form1 in ProjA do a .Show() for Form2 in ProjB? I tried
the following, but I get a problem with the reference

Sub ShowFormB
Dim frm as new < ? FormB?? various things I tried here>
frm.Show()
Me.Close()
End Sub

Thanks
 
G

Guest

MikeB,

ProjA must have a reference to ProjB. In the Solution Explorer window,
right-click ProjA and select Add Reference. From the Add Reference dialog,
click the Projects tab and select ProjB.

Now your ProjA can show a form in ProjB:

Dim frm As New ProjB.SomeForm
frm.Show()

Kerry Moorman
 
M

Mythran

Kerry Moorman said:
MikeB,

ProjA must have a reference to ProjB. In the Solution Explorer window,
right-click ProjA and select Add Reference. From the Add Reference dialog,
click the Projects tab and select ProjB.

Now your ProjA can show a form in ProjB:

Dim frm As New ProjB.SomeForm
frm.Show()

Kerry Moorman

This is kinda tricky. What I would prefer in my own projects would be to
create a separate library project for the shared forms. This project would
then be referenced by the two winforms projects. This prevents circular
references from occurring.

HTH,
Mythran
 
M

MikeB

Kerry, thank you.

Does this mean that the Projects have to have names consisting of one
word only? Is there a way to (for instance) use "Host Country" and
"Travel Information" as project names?

MikeB
 
G

Guest

MikeB,

You can have mutliple word project names, such as "Host Country". But I
think that the space gets replaced by an underscore by .Net, like this:

Dim frm As New Host_Country.SomeForm

Kerry Moorman
 
H

Herfried K. Wagner [MVP]

Kerry Moorman said:
You can have mutliple word project names, such as "Host Country". But I
think that the space gets replaced by an underscore by .Net, like this:

Dim frm As New Host_Country.SomeForm

In this case I'd set a more appropriate root namespace in the project
properties.
 
G

Guest

That's all well and good but when you are writing and debugging code, it's a
pain to load the library class and change it's code...also hard to find some
errors. That's the beauty of putting all your related projects into one
solution at least until you've finished debugging them.
 
M

Mythran

Dennis said:
That's all well and good but when you are writing and debugging code, it's
a
pain to load the library class and change it's code...also hard to find
some
errors. That's the beauty of putting all your related projects into one
solution at least until you've finished debugging them.

Yeah, you would put these shared forms into a project that is part of the
same solution and reference this project as a project reference from the two
winforms projects.

Mythran
 

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

Similar Threads


Top