简体   繁体   中英

Add vb.net forms to c# project

In vb.net, the Login Form , Splash Screen , and Dialog Form are nice to have. They are available through Visual Studio's Project > Add New Item... dialog.

Is there a way to add these prebuilt forms to ac# project without jumping through hoops?

If need be, the forms can be re-implemented or created in a vb.net project and then instantiated from the main (c#) project, but that is a lot of work if there's an easy workaround.


vb.net project


c# project

I think using VB.NET forms in C# is not directly possible. But you could put a wrapper around the VB.NET forms and compile it into a DLL. Then you can use the DLL from your C# application. A similar suggestion (but the other way round) is given here .

Edit: Actually you don't need a wrapper. You can use the form from the project directly as shown here .

You can create your own C# versions of the VB templates by (manually) converting the .zip files in C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Common7\\IDE\\ItemTemplates\\VisualBasic\\Windows Forms\\1033.

  1. Copy and unzip the required template
  2. Manually convert the VB code to C# code
  3. Modify, and save the .vstemplate XML file (see also the schema reference)
  4. Compress the files into a new .zip
  5. Drop the C# .zip inside C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Common7\\IDE\\ItemTemplates\\CSharp\\Windows Forms\\1033

No, you can't combine multiple languages in one project. Simply create a separate project for your VB.NET forms library.

you cannot mix VB and C# in the same project but you can combine/group a C# project and a VB.NET project into the same VS solution .

in this case you could have a class library written in vb.net which hosts your special forms and a windows application written in C# which references the other one and uses those forms, provided you make those public.

Only thing I can think of is to make the primary project of your application a VB project. That's the only thing that'll allow you to use the My.Application.SplashScreen property, and you'll only be able to use it from within the VB parts of your app (trying to use Application.SplashScreen from within C# will not compile).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM