5

I have a c# and vb .net solution. I need to use the c# form inside vb form as a tab. How can I do this?

Vicky
  • 1,657
  • 6
  • 23
  • 33

4 Answers4

16

You could create one of the forms in a separate class library or as a user control in a separate class library and just reference it from within your application. Each project in your solution can be either VB.Net or C#, so it works both ways...

In a simple example solution you could have the following projects

  • MyApp.CSharpControls - Project in C#
  • MyApp.VBControls - Project in Vb.Net
  • MyApp.UI - Project in either C# or VB.Net which can reference either of the other control projects

Edit
I'm presuming winforms??

davidsleeps
  • 9,393
  • 11
  • 59
  • 73
  • 3
    You don't even have to convert it to class library project. The vb solution can add a reference to the .exe generated by the c# solution and use any of the public types in that c# solution. It will help to convert the c# form to a user control, though. – Joel Coehoorn Apr 12 '11 at 04:54
6

You would need to have Visual Studio Professional to do something like this.

Instead I suggest you use this site to convert your C#.net to VB.net http://www.developerfusion.com/tools/convert/csharp-to-vb/

Craig White
  • 13,492
  • 4
  • 23
  • 36
4

No, you can't.
I suggest to encapsulte the the c#-Form into a separate assembly. Create a UserControl to use it inside the other application or if you need the complete form, encapsulte it into a DLL and export a Show/ShowDialog() method.

Markus
  • 4,487
  • 3
  • 41
  • 51
  • 2
    You can add a reference to a project for plain .Net exe files, as well as class library dlls, and still use any public type in that exe file. There's no special work involved for that, it's still just an assembly. – Joel Coehoorn Apr 12 '11 at 04:55
  • 4
    Of course this is possible, but I try to prevent(or don't like) to instantiate public classes from an exe-file. This was a suggestion, not a "what is possible". The sentence 'No, you can't' refers to the mixture of c# and vb in one solution. – Markus Apr 12 '11 at 05:01
  • Sorry davidsleeps, yes I mean project. – Markus Apr 12 '11 at 05:16
  • Can I use the form of exe I added in a TabControl? – Vicky Apr 14 '11 at 12:58
1

I did it by adding the .exe file of VB project as a reference in the C# project and called the Form.Show() of the VB project.

Vicky
  • 1,657
  • 6
  • 23
  • 33