Use of Forms from one Project in a different Project in Visual Basic Express2008

kumarbabu
kumarbabu used Ask the Experts™
on
The programming language is Microsoft Visual Basic Express 2008.

I have a form that I created in one project. This does a bunch of functions. I like to include this entire form in a different Project. For example a scenario I have in mind is as follows:

Assume I have two projects, ProjectOne and ProjectTwo. In Project One there is a Form1 that does some useful functions including capturing data. This project was done some time ago. Now I have a new Project i.e. ProjectTwo where I do other things but I also need to do the functions in ProjectOne. Instead of redoing everything, is there a way that I can import Form1 in its entirety from ProjectOne into ProjectTwo. If so, how?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Question is if you want future changes of the form should be reflected in both projects.

If not, just copy the form to projectTwo.
If yes, you should use the library concept: To the solution of projectOne add a new project of type Windows-control-library. Convert the relevant forms into UserControl's in the library.

In ProjectTwo, add reference to this library and use it.

Commented:
best way is to copy form1.vb form1.designer.vb and if present form1.resx to the folder containing the newer project, then right click on your project inside Visual Studio, Add Existing items - Select all files (form1.vb,form1.designer.vb,form1.resx) and click add.


hope this helps!

Author

Commented:
1. I forgot to mention that Form1 from ProjectOne uses a bunch of libraries. By just adding the existing items I get a lot of compiler errors when I try to compile them.  I need to be able to include everything from Form1 in ProjectTwo.
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

Commented:
I don't think there is an easy way to do this, check which libraries are used in the form, copy the dlls to project 2. After adding the form, go to the properties and add all dll's as reference.

An easier way is just add the entire project, but then you get a dll from project1 when building project2...

Author

Commented:
How do you add an entire project?

Would it make more sense if I created Form1 (from Project1) as an executable and then called it from Project2?

Commented:
no don't do that...

Just go to solution explorer (usually right-hand side), click or select on your solution, right click Add - Existing Project.

Best make a copy of the entire project and place this in the same folder (or to a place that makes sense to you)

This way if you build the project ( make sure the old project is build first ), you will get a dll of project 1besides the exe you meant to create for project 2, in the same bin\debug or release folder

Author

Commented:
I am not sure I understand. I went to Form1 in Project1 and right clicked on solution explorer. What I get is as shown in the attached jpeg file. I don't see any "Add Existing Project". Could you please give me more details - step by step perhaps?
soln-explorermenu.JPG

Commented:
I'm sorry, you need to add it through File - Add - Existing Project
The way to do this, I previously suggested is only available if more then 1 project is already in your solution.
Clipboard01.jpg

Author

Commented:
Thanks for the clarification. As per your advice, I was able to add the project "CaptureAndSave" to my existing project.. I tried to use CaptureAndSAve form from my Form3 as shown below:
Public Class Form3
    Dim Testform As New CaptureAndSave
.........
.........
    Testform.ShowDialog()

When I tried to build the new project, I get a compilation error saying that "Type Capture and Save Not Defined". Please see attached jpeg file.
addproject.JPG

Commented:
You have to make sure that the build order of your project, builds that project first before building the main project...

Hope this helps?
Clipboard01.jpg

Author

Commented:
Thanks for the update. I changed the build order. I still get the same compilation message as before. I am attaching a copy of the build order screen. The form is called CaptureAndSave but the binary executable is called LS_VB.

Author

Commented:
I forgot to attach the jpeg file for build order. Here it is .
build-order.JPG

Commented:
Yes indeed I forgot to mention something, you have to change the project 2 to be a Class Library instead of a windows form.

Then you should be able to call upon the forms

See if this solves your issue.
Clipboard01.jpg

Author

Commented:
How do you change Project2 to be a class library. Do you still do everything else the same as you had indicated?
Commented:
yes you do...

On the previous post, you see the image? Change the application type from windows form to class library.. (properties of project 2)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial