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:
Before running it
There are a couple of things you should do before running this application:
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.