This is partially related to this thread Combining two projects and get a single .sln file.
What are the correct syntax to call the forms on these projects. For example, if Solution1 contains Project1 and Project2, ...and... Project1 has Form1.vb & Project2 has Form1.vb. So what is the syntax to call Form1.vb in Project2 from Form1.vb in Project1 (assuming there is a button to click and open a form on click event).
Just a note however, I've added Project1 & Project2 to Solution1 as well as added a reference to My Project.Resources.Designer.vb.dll.
But when I tried to call Form1.vb in Project2 from Project1, I got syntax error - Project2.Form1 is not defined.
Can someone point me in the right direction?
Any help is greatly appreciated. Thanks in advance.
Project1 is bold hence the startup project.
Public Class Form1 of Project 1: -
Public Class Form1 of Project 2: -
Error message: -
Don't have the option to select "Import Namespace": -
This is how the form Project1 looks like: -
My Reference Manager => Solution option is empty
Let say, if I want to browse to the reference file in Solution => Projects option above, which file type should I choose ??
a. Visual Basic Project file
b. USER File
c. VSPSCC File
How to call Form1 (in olAddIn_With_Form1) from Project1 (Startup project) ?
Answer:
Add the .dll via Reference Manager window then browse to ...\bin\Debug\olAddIn_With_Form1.dll
Dim myolAddIn_With_Form1Form1 As New olAddIn_With_Form1.Form1
myolAddIn_With_Form1Form1.ShowDialog()
For kicks, I try to add the whole project via "Add as link" method and I got this error message
Select Visual Studio menu Project -> Add Existing Item... Then select (browse) in the file dialog the Form. cs (Form = name of the form) you want to add to the project and the form (with all associated files) is (copied and) added to your project.
You need to add a reference to the 3rd project in your 1st project. To do this, right-click on your project, select "Add Reference," then select the project in your solution. Once your main project references the 3rd project, then you can access its public types.
So, to answer with some screenshots:
First create your two projects. The project that is the startup project (in your example and in mine, that would be Project1) needs to know about the other solution. To do this, we need to add the reference to the project, right click on Project1 and click on 'Add reference...'
Then, use the solution option in the sidebar, to click the checkbox on Project2
And then you can add the project in your code using the Project2.Form1 identifier, as such
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim frmOtherProject As New Project2.Form1
frmOtherProject.Show()
End Sub
End Class
or, in case your form in the second project doesn't have a biased name (form1 currently exists 2 times, so lets rename it as form2), you can import the second project and use it's classes directly as such
Imports Project2
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim frmOtherProject As New Form2
frmOtherProject.Show()
End Sub
End Class
I used Visual Studio 2012 as a basis, but the principle should be the same ;)
ADDITION
I might point out that this will not be your typical style of referencing the projects, mostly you will separate your application by levels of concern, by adding, for example:
There are of course plenty of ways to arrange your application in a meaningful structure, but I find that this one is a good example on how you can structure your application in a meaningful way
UPDATE
As an update still, getting your solutions to share code, shouldn't be this hard, if you write your code so that it can be reused. By sharing the logic and the harder code inside a class library that can be shared over both solutions, you only have to rewrite the Presentation layer (how you display the data). And you can do it more specifically for the environment you want to work with.
In the end, your Outlook Addin Solution and Your windows forms project could share the code that requests the resources, or loads the data, or does some other complex calculations, and the only code you have to "reproduce" is how you show it on the screen. So according to the environment you can present the data in a better way, specific to that environment, but share the logic and the models you use in both (or more) environments.
This way, you development time is cut down, and your code becomes less error prone, because you don't have the same code several times, as an example, see the following screenshot:
As you can see, there is a shared library, that is referenced by the outlook addin and by the windows form application. Neither the Forms application nor the outlook application know about each other, and they also shouldn't, as they have essentially nothing to do with the other.
So, although, my latest update doesn't answer your question, I still think it's the better way to arrange your code. If you would later want to make a website reusing the code you made, you only need to make an extra presentation layer, and reuse the code from the SharedLibrary once again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With