简体   繁体   English

如何将Windows窗体应用程序从C#转换为VB?

[英]How do I convert a windows forms app from C# to VB?

I've been converting all kinds of other things, classes, interfaces, ASP.NET MVC apps, and WPF applications, but I am stumped as to how to convert a windows forms application, as the whole structure seems to be different. 我一直在转换各种其他东西,类,接口,ASP.NET MVC应用程序和WPF应用程序,但是由于整个结构似乎不同,我对如何转换Windows窗体应用程序感到困惑。 Does anyone have any advice on how to tackle this problem? 有人对如何解决这个问题有任何建议吗?

I see essentially that you have two files, Form1.cs and Form1.Designer.cs. 我基本上看到您有两个文件,Form1.cs和Form1.Designer.cs。 Literally translating them from C# to VB doesn't work because of some intricacies or other of how Visual Basic works. 从字面上将它们从C#转换为VB是行不通的,因为Visual Basic的工作有些复杂性或其他原因。 I think you /might/ be able to convert Form1.cs in this way, as it's just a constructor plus event handlers, but the designer contains the references to the controls etc. and I am not sure how to go about doing that. 我认为您/可能/能够以这种方式转换Form1.cs,因为它只是构造函数和事件处理程序,但是设计器包含对控件等的引用,因此我不确定该怎么做。

I am using Visual Studio 2010 Beta 2. 我正在使用Visual Studio 2010 Beta 2。

My approach would be to create a new form in VB do add some forms and add events and look at the VB generated from there you will be able to see how each element [control/event/propertyset] is done in both C# and VB. 我的方法是在VB中创建一个新表单,添加一些表单并添加事件,然后查看从那里生成的VB,您将能够看到在C#和VB中如何完成每个元素[control / event / propertyset]。 From there it should be trival to conver from c# to VB.net. 从那里,从c#转换到VB.net应该很简单。 This would give me more confidance the designer could cope with the converted class as well as the runtime. 这将使我更加自信,设计人员可以应对转换后的类以及运行时。

What I did is to manually create a new form in VB with the same name as the form in C#, then opened the C# form in design view, made sure that I selected all controls on the form, copied and pasted them onto the empty new form in VB. 我要做的是在VB中手动创建一个与C#中的窗体同名的新窗体,然后在设计视图中打开C#窗体,确保选择了窗体上的所有控件,将它们复制并粘贴到空的新控件中。 VB中的表格。 Then just translated the code-behind with the telerik free converter at: converter.telerik.com . 然后,只需在以下地址使用telerik free转换器翻译背后的代码: converter.telerik.com I'm sure it becomes cumbersome if you have a huge solution that you need to convert, but in my case it was a small solution and the results were great. 我敢肯定,如果您有一个需要转换的庞大解决方案,那么它将变得很麻烦,但就我而言,这是一个很小的解决方案,并且效果很好。

Redgate.NET Reflector做得很好。

The two files each contain a part of the Form1 class, in the form of partial classes. 这两个文件每个都以部分类的形式包含Form1类的一部分。 As partial classes are also supported in VB.Net, I don't see a problem here. 由于VB.Net也支持部分类,因此在这里我看不到问题。

The designer file contains all of the code generated by the windows forms designer, the Form1.cs file is the place where all custom code goes (event handling, etc). 设计器文件包含Windows窗体设计器生成的所有代码,Form1.cs文件是所有自定义代码所经过的地方(事件处理等)。

So after converting both files you should check if all references made to controls in the Forms1.cs file are available in the designer.cs file. 因此,在转换完两个文件之后,您应该检查是否对designer.cs文件中的Forms1.cs文件中的控件进行了所有引用。

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

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