简体   繁体   English

在 C# 函数中打开 VB.NET 窗体

[英]Open VB.NET Form inside C# function

I wonder if you can open a VB.NET form1 from C# form1 like VB.NET Form1.Show();我想知道你是否可以像VB.NET Form1.Show();一样从C# form1 打开一个VB.NET form1 Form1.Show(); inside the button function of the C# code.C#代码的按钮函数中。 I just thought of this will trying learn various code in them, can someone help to verify if this is possible???我只是想到这将尝试学习其中的各种代码,有人可以帮助验证这是否可行吗???

The answer is Yes, but you can't have C# and VB.net in a single project.答案是肯定的,但不能在一个项目中同时使用 C# 和 VB.net。 So create a solution containing two projects, one in C# the other in Vb.Net and you can open the vb.Net project form in C# as you suggest.因此,创建一个包含两个项目的解决方案,一个在 C# 中,另一个在 Vb.Net 中,您可以按照您的建议在 C# 中打开 vb.Net 项目表单。

There is one major consideration though - that's dependencies.但是有一个主要考虑因素 - 那是依赖性。 For this to work, the vb.net project is a dependency of the c# project, so the C# project sees all the VB.Net project but not the other way around.为此,vb.net 项目是 c# 项目的依赖项,因此 C# 项目可以看到所有 VB.Net 项目,但反之则不然。

It is possible to configure the solution to make both projects reference eachother - here's a post about it.可以配置解决方案使两个项目相互引用 - 这是一篇关于它的帖子。 Reference in two projects 两个项目中的参考

However that's complicated and so I'd suggest having a third project (or fourth if needed) that contains any code you want to have common to both the VB and C# projects as a dependency to them both.然而,这很复杂,所以我建议有一个第三个项目(或第四个,如果需要的话),其中包含您希望 VB 和 C# 项目共有的任何代码,作为对它们的依赖。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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