1

Good Day All,

I’m new to programming. I’m using Visual Studio 2010. I’m taking into two introduction classes, VB and C# with .Net.

I'm searching for example code of different project forms under the same solution working together at least at my level of understanding. The only alternative that I can fathom is that this is not allowed.

I may need help in forming my question since my searches are all failing. I've listed all my failed search strings at the end of this document.

We have created four school projects with single forms under different solutions that also have classes.

Can the four VB projects be combined under a single solution so that the frmCompany can “.show()” the frmCustomerAccount or the frmMovieRental or the frmPayment . Each of these forms are under their own project but I have “add existing” them into a single solution. I want to know if the multiple project forms can call each other. Or how do you combine projects so that they work together.

Do you use “pathing” when referring or calling across projects within the same solution? I’m trying to move between their forms. If you can do this, how do you make the call between projects? Such as from project1’s form: “project2.frmCustomerAccount.show()” ? and back again by “project1.frmCompany.show()” ?

I’m hoping for simple code examples that shows bouncing between multiple projects' forms under a single solution that I may understand at my intro level.

Thank you for reading, William

Below are my list of Google searches Visual basic 2010 can projects reference other projects forms visual basic 2010 can projects work together visual basic 2010 how do you join projects "visual studio 2010" "multiple projects" tutorial "visual studio 2010" do projects work together call each other? "visual studio 2010" how does one project refer to another within a solution? "visual studio 2010" "how do you use forms from other projects? "visual studio 2010" "how do you integrate projects? "visual studio 2010" "do projects integrate? "visual studio 2010" "do projects tie together? "visual studio 2010" can forms call forms in other projects "visual studio 2010" what relationship do projects have within the same solution "visual studio 2010" "do projects combine?"

William
  • 15
  • 3
  • 8

1 Answers1

1

A Solution is simply a Visual Studio construct meant to help you to do what you just did. Group up a few projects so that you can easily jump back and forth between them. From the compilers standpoint however, the solution doesn't matter.

What matters are referencing the assembly you need and using the correct namespace. So what you need to do in a visual studio setting is to select Add Reference from the context menu of the References node in a project. Then look up the project containing the form you want to call, and add it.

From your calling class you can then either do a

//Header of file with class initializing referenced class.
using Personal.Namespace.Of.Other.Class;

//Within initializing class-method.
var form = new MyForm();
form.Show();

or

var form = new Personal.Namespace.Of.Other.Class.MyForm();
form.Show();

Hope that'll get you on the right track.

Gaute Løken
  • 7,522
  • 3
  • 20
  • 38
  • My startup Project4 can now call an instance of Project1’s form but how do I go back to Project4’s calling form? I’m getting “not defined” and not declared errors trying to use the same code from above. Thanks, William – William Nov 05 '11 at 22:07
  • Project#4 has a reference to Project#1. Mithon’s response allowed me to have Project#4 call Project#1’s Form. However, it does not seem to allow me to return using the same code to Project#4’s calling form. Is adding a reference a one way street? How do I return to Project#4’s calling form from Project#1 called form? – William Nov 05 '11 at 23:04
  • I'm not sure I understand what you're trying to accomplish. You should try to avoid cyclic dependencies. That is.. don't reference project1 from project4 and also reference project4 from project1. It causes build headches and lots of other bad problems in bigger solutions. If you need project4 to react to stuff in project1, register with some events and raise them as appropriate. If you just need a return value when the form from project4 closes, then you can call ShowDialog() instead of Show(), and use result values stored in the returned DialogResult. – Gaute Løken Nov 05 '11 at 23:06
  • Also, if you absolutely have to have access back again, you can pass the parent in as an argument to the constructor of the child. If the argument then is of type Form in stead of your Project4.MyForm, then you don't get the cyclic dependency problem at all, and everything is good. You'll have to specify that constructor though. – Gaute Løken Nov 05 '11 at 23:09
  • I have four projects that each have forms. I was hoping to use these forms together the same as multiple forms in a single project where you click on a button on each form to move to the next form. At this point I do not need to return a value just to be able to move from any form to any form among my four projects. – William Nov 05 '11 at 23:16
  • Sorry to ask but how do you code the above to pass the parent in as an argument to the constructor of the child to be able to move from any form to any form among my four projects? – William Nov 05 '11 at 23:36
  • What you want is a wizard, sometimes named cards. You might want to look at this: http://www.codeproject.com/KB/cs/WizardDemo.aspx. Your problem here is that you're layering your application by the wrong thing. Each form is part of the wizard, which is one concept with one job and should probably be in one assembly (project). Sometimes that GUI-assembly will make use of complex algorithms etc residing in another assembly for what's known as the business layer. This in turn may use a data access layer (DAL) in another assembly. Most likely you don't have these needs. – Gaute Løken Nov 05 '11 at 23:55
  • To be able to pass in custom objects into your Forms, you will have to subclass Form (which you've probably allready done) and add your own custom constructor public MyForm1(Form parent, Form nextForm). Then store these in a local variable, and use them when the next button is clicked. – Gaute Løken Nov 05 '11 at 23:58
  • Understood "should probably be in one assembly (project)". So what I need now are links or directions on how to properly and efficiently move the correct project elements from multiple projects into a single project . . . or at least an explanation of this process for forms and multiple classes. – William Nov 06 '11 at 02:46
  • Drag and drop will serve. It will create a copy of whatever element. You can then delete the source element. Remember to change the namespace of each thing so you have less headaches with using statements. – Gaute Løken Nov 06 '11 at 14:51