(Print this page)

Visual Basic Windows Forms conversion assistant
Published date: Sunday, September 7, 2008
On: Moer and Éric Moreau's web site

If you adopted VB.Net when it first appeared in Visual Studio 2002, you probably have some projects and/or forms here and there that followed you towards the years.

If you remember when Visual Studio 2005 was released, the format of the files changed a bit. Instead of adding a “Windows Form Designer Generated Code” region at the top of your code, Microsoft decided to isolate this code into a new .designer.vb file. When you upgraded projects from Visual Studio 2002/2003 to Visual Studio 2005 or 2008, this “untouchable” region remained right there.

This month article will be a bit different. Instead of focusing on a specific topic, I provide you a little tool (no strings attached). This little tool should convert those forms from the old “all-in-one” file to the newer format.

Technologies used in this article

Only Visual Basic 2008 is required to use the code included in this article.

Credits

This little tool has been published before by Tim Saunders (nickname “Aspnot” in VBForums) and is available from http://www.vbforums.com/showthread.php?t=376899 but it was targeting Visual Studio 2005. Later, “whatsit2002” (nickname on Experts Exchange) modified it to be able to target Visual Studio 2008.

I then modified it myself to add some features:

  • Tracing to be able to see what’s happening.
  • Detecting if a form is already in the newest format (for projects that mix old and new file formats).
  • Fixing some encoding problems I had with French characters.

Before running it

There are a couple of things you should do before running this application:

  • The solution you will convert must already have been opened in Visual Studio 2005 or Visual Studio 2008. If you don’t do it, you will get an error message (see the CheckForVersionNumber method).
  • If your project is under source control, do full checkouts otherwise it may fail for access denied.
  • Take a full backup of your project. This tool overwrites the files in place without further notice.

How it works

The first thing you need to do is to click the Browse button to navigate to a solution file (.sln). After a solution has been selected, all the projects it contains will be displayed into the CheckListBox control (see the LoadProjectList method). You now have the options of selecting the project(s) you want to convert.

Figure 1: The demo application in action

You are now ready to push the Process button which will convert the Windows forms of the selected VB projects skipping C-Sharp projects (see the Process_VBPROJ method) that don’t already have a designer form (see the Process_FORM method).

Conclusion

I don’t like the “Windows Form Designer Generated Code” region at the top of my code file created by early versions of Visual Studio (namely 2002 and 2003). I prefer by far the .designer.vb files. Sadly, when upgrading projects, that region remained there.

This is where this little tool may help you. It is probably not THE perfect tool but I never found any other. I fixed with the problems I had while converting my own projects.

I hope you will find it useful.


(Print this page)