3

A friend of mine and me were working on a project for class. He prefers VB and I prefer C#, so we just did our thing. Now, we were thinking of merging the projects. I added his into mine, but I can't find how to open the forms he has made from the forms I made.

Is there any way to launch VB forms from a C# form?

Simon Verbeke
  • 2,905
  • 8
  • 36
  • 55

6 Answers6

7

Language is project specific. Meaning you have a C# project and VB project. You cannot mix multiple languages in one project. You can however have multiple languages projects in a solution. E.g he does the front-end in VB and you do the back end in c# and then add references in the vb project to the c# project.

Additionally, you could use a VB to C# converter or vice versa with mixed results. I've converted entire vb projects to c#.

Michael Rice
  • 1,173
  • 5
  • 13
  • But the problem is that we've both made forms, thinking we wouldn't be merging it. I know that you can add C# dll's to a VB project and the other way around. But I would like to open his forms. (Or am I just not understanding you) – Simon Verbeke Mar 14 '12 at 15:00
  • I believe you could open his form from the dll if it's exposed as public. One project will have to be the "master" that will do the application loading though. – Michael Rice Mar 14 '12 at 15:02
  • Alright, I'll look into that :) Or maybe just translating and recreating his forms. – Simon Verbeke Mar 14 '12 at 15:04
4

You can't add different languages to the same project, but you should be able to add both projects to the same solution, and add a reference from your C# project to his VB project, and use the types he's created - so long as they're public, of course.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
4

It is not possible to mix C# in VB. but you can use approach suggested by Jon Skeet.

1) Create Multi-Project Solutions

2) Add Reference of your friend's VB project in your project

Then you can create object of those forms that your friend created as:

YourFriendProject.SomeForm  someForm = new YourFriendProject.SomeForm();
someForm.Show();
Niranjan Singh
  • 18,017
  • 2
  • 42
  • 75
1

The answer has already been posted, just adding a picture to make things a bit more clearer.

  • You cannot add forms / code from two different languages to the same project.
  • You can add a project reference from the VB assembly to the CS assembly and vica versa.
  • You can add either project to the other solution to have access to both.

enter image description here

Alex
  • 7,901
  • 1
  • 41
  • 56
0

This is how I did it. C# opening VB.NET. I also added sCarletto as a reference, but trying to add my main C# for as a reference to sCarletto, I wasn't so successful...yet. On voice command Araura (form1) opens sCarletto (vb.net) form. enter image description here

0

Here's a real simple solution I overlooked due to being burnt out on coding. I simply did this:

Case "ARAURA COME BACK"
Process.Start("The file path to my C# programs .exe located in the Debugging folder")
me.Close()
          
ChrisF
  • 134,786
  • 31
  • 255
  • 325
  • Sorry for the separation issue above. I had it spaced out beneath each other, but it spit it back this way. You can find my projects at: github.com/deadreport77 – Justin Linwood Ross Jul 29 '21 at 21:00