Over the past several months I’ve been getting up to speed on WinForms. For the previous 5+ years I’ve been doing web based software development. During those wonderful years I created many little utilities using WinForms (or VB6!?!?). Even the most complicated of my WinForms experiments was peanuts in comparison to what any “real” WinForms developer has developed.
During my time in the web world I learned one very important lessen: NEVER use the Web Forms designer! Not only does it create horrendous HTML, but it also deletes code, removes event handlers, and causes overall havoc on your project. Luckily VS 2005 fixes most, if not all, of those problems.
Now that I’ve gotten off topic a bit lets get back to the question at hand….is the WinForms designer evil?
The WinForms designer makes developing complex forms feel quick and painless. The drag-and-drop’ability allows you to throw together new forms in no time flat. It allows you to hook up event handlers and plug in the code that should be executed when those events fire using a couple mouse clicks. What this all leads to is a great environment for building prototype applications. What it doesn’t lead to is well architected WinForm applications. Just using the WinForms designer doesn’t do anything to help with the testability of your application. If your application can’t be tested it’s not well architected.
The hardest thing to unit test in an automated way is a Gui. Do yourself a favor and DON’T use the WinForms designer. Think of ways you can make your application testable. Evaluate what you should do in the designer and what you shouldn’t. If the things that you deem as “should do in the designer” outweigh the things that you deem “should not be done in the designer” then start your list over. Repeat until very few things are in your do in the designer list. While I don’t think the WinForms design is outright evil I do think it should only be used in moderation. Use MVP, don’t use that designer.