Link to home
Start Free TrialLog in
Avatar of kumarbabu
kumarbabuFlag for United States of America

asked on

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

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?
Avatar of danirk2
danirk2

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.
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!
Avatar of kumarbabu

ASKER

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.
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...
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?
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
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
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
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
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
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.
I forgot to attach the jpeg file for build order. Here it is .
build-order.JPG
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
How do you change Project2 to be a class library. Do you still do everything else the same as you had indicated?
ASKER CERTIFIED SOLUTION
Avatar of Kraeven
Kraeven
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial