开发者

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. 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. Literally translating them from C# to VB开发者_Go百科 doesn't work because of some intricacies or other of how Visual Basic works. 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.

I am using 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. From there it should be trival to conver from c# to 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. Then just translated the code-behind with the telerik free converter at: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 does a great job.


The two files each contain a part of the Form1 class, in the form of partial classes. As partial classes are also supported in VB.Net, I don't see a problem here.

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).

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜