How to access other forms in a solution

2

22Pom

Hi All,

Thanks to Family Tree Mike I've managed to get a Solution up and running,
now comes the fun part.

How do I call forms from other Class Libraries and how do I use a Background
form behind other forms in different Class Libraries?

Best Rgds
22Pom
 
E

eBob.com

I am not sure what you mean by a "Background form", but the first part of
your questions is pretty easy. Go to Project > Add Windows Form... and
create your "subform". Let's assume you accepted the default name of Form2.
Then back in Form1 code all you need to do is ...

Dim f2 as new Form2
f2.Show

I suspect you'll have more questions but this should get you started.

Bob
 
2

22Pom

Hi eBob.com

Thanks for your reply.

What I have is one form, Background, that is basically a pictire covering
the whole screen. It is classed as a Parent form and all other forms as
Childs. The Parent form remains visible all the time and the childs open and
close as you move through the program.

Now this Background form is in one Class Library of my Solution and I need
to access this from another Class Library of my Solution.

Thanks
22Pom
 
F

Family Tree Mike

I'm assuming you have something like Project1, which contains the class
MainForm, and Project2 which has the class ChildForm.

In your Project1, add a reference. The dialog that pops up will have a .Net
tab, a COM tab, then Projects tab. The projects tab should show Project2.
Add it as a reference. Now in Project1.MainForm, you can instantiate a
ChildForm as:

Dim c as New Project2.ChildForm

The rest of your post sounds like you are talking about a Multi Document
Interface. The key steps in this would be to set your
MainForm.IsMdiContainer = true, and when you create the ChildForm, to set
the ChildForm.MdiParent to be the MainForm.
 
2

22Pom

Hi Family Tree Mike,

If I could post a screen shot of my Solution it would help you understand
things better.

I have created a Multi-Project Solution that has 5 Class Libraries. In one
called StartUp I have an Exit Module with the following code:

Module ModExit

Public cancel As Integer
Public Sub ExitProc()

Dim response As Integer

response = MsgBox("End Program Now", vbYesNo + vbQuestion)
If response = vbYes Then


Application.Exit()
ElseIf response = vbNo Then
cancel = 1
End If
End Sub

End Module

This works fine if I want to exit my program from here, but I can't seem to
access this from another anywhere else. If I create another module in
another class and copy the code over I get an error on "Application", so that
won't work.

I have various points in my program where the user can opt to exit so how to
access the original is my problem.
 
F

Family Tree Mike

This same topic is being discussed in a thread called "Can an MDI child
close and MDI parent?".

Generally I raise an event from the child form to the calling application.
The calling application (which has your module modexit), catches the event
and closes the application.
 
2

22Pom

Hi Family Tree Mike,

What I tried in the Child Form (CentrifugalSplash) was the following:

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click

ExitProc()

End Sub

which is what I had used before in my very large program, and it worked just
fine. Unfortunately it gives me an error on the "ExitProc()" saying that it
is not declared. I tried many ways to overcome this without success.

Thanks
22Pom
 
F

Family Tree Mike

ExitProc() must be a routine in your program (the very large program, as you
say). It is not a method that is in MSDN, that I can find. I found a few
hits as to ExitProc in Delphi.

In your large project, presumably, you should be able to highlight an
occurance of ExitProc, and right click to get the option "Go to Definition".
This should help identify what ExitProc is.
 
2

22Pom

Hi Family Tree Mike,

Yes it's a Module that holds the code I put up in an earlier message, it's
getting the program to call it from another class. I'm trying another way
around this and if I find a solution I'll post it for all to use.

Rgds,
22Pom
 
F

Family Tree Mike

OK, modules cannot be shared (to my knowledge) from DLLs. I do more in C#
than VB, but I believe that one way would be to make a shared public method
in a utility class from your dll, or a utility dll. You don't want to put
it into a class in the main application project, as that would cause a
circular reference problem.
 
2

22Pom

Hi Family Tree Mike,

I don't know. I think I'll give up on this, I can't seem to work it out.
I've tried all things that I can think of without success. If I move it to
another area I get a different error. If I try to access it using it's full
address path I get other errors, so I think I'l go back to adding a lot of
duplicated code and hope for the best.

Thanks anyway for your input.

Best Rgds,
22Pom
 

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