Implementing a Custom Forms Designer in .NET

Update: I have started a series of posts which will build towards implementing as full-featured design surface as I can manage.  The series begins here.

Over the past few years, I have been doing some research on implementing a forms design surface within a program.  I see it as a way to provide a visual design connection for my next major project when we move a VB6 program that is very forms intensive to one that is much less so and is focused on user design and documents.  Here are some of the references I have found on the subject.

June 2002: MSDN, Creating a Design Surface Using Windows Forms and GDI+ in Microsoft .NET \article and code: [DesignSurface.exe]

This effort was the first wholly manual version that I came across and only handled simple shapes.  When I understood what was going on, I realized that it was trying to duplicate much of what was in Visual Studio using a brute force approach.  This was way too much work when what I wanted was already in the Framework.  I did not like the idea of doing so much work, so I waited.

June 2003: Website, Hosting Windows Forms Designers, [article and code: hosting.zip]

Tim Dawson comes out with the first article describing of how the forms designer in Visual Studio worked.  This is a great article and seems to have been the first detailed description of the process and classes required.  Excellent.

June 2003: Website, SharpDevelop, [see site for description and code]

Around this same time, the SharpDevelop folks were working on their open source Visual Studio substitute, now in version 1.0.  This included implementing a design surface using much the same technique as Visual Studio.  The down side of their work is that it was highly dependent on their system, especially their complex plug-in architecture.  I found the Dawson article somewhat confusing and the SharpDevelop implementation very confusing.  Since I was not in need of immediate action, I waited.

August 2004: Microsoft Knowledgebase, INFO: Code Sample That Demonstrates How to Create a Custom Form Designer by Using Visual C# .NET \article and code: [DesignerHost.exe]

This is a very basic article that essentially just points to the code sample for the explanation.  This is a good example.  Importantly, it implements the serialization interface that is necessary for cut, copy, and paste, as well as undo and redo.

December 2004: MSDN Magazine, .NET Internals: Tailor Your Application by Building a Custom Forms Designer with .NET \article and code: [CustomFormsDesigner.exe]

Now MSDN Magazine has published what I consider to be an authoritative article that clears up some of the confusion in the Dawson article.  This is essential info in understanding how the framework designer works and what needs to be provided by the programmer.  Highly recommended, even mandatory if you are trying to do this

A weakness of this entire process is that there is little documentation other than the articles on how everything is supposed to be glued together.  Each interface or supporting class has a basic description available, but little in the way of detailed interaction is explained.  The MSDN Magazine article lists some of the required services, but not all.  Here are some additional hints at completing a full-featured design surface.

This capability is highly dependent on implementing interfaces, and there are quite a few of those.  As stated in the referenced documents above, implementing one of these is not easy.  Here are links to some of those interfaces.

IComponent
IComponentChangeService
IContainer
IDesigner
IDesignerEventService
IDesignerFilter
IDesignerHost
IDesignerOptionService
IDesignerSerializationService
IDictionaryService
IExtenderListService
IExtenderProviderService
IMenuCommandService
INameCreationService
IRootDesigner
ISelectionService
IServiceContainer
IServiceProvider
ISite
IToolboxService
ITypeDescriptorFilterService
ITypeResolutionService

This article is part of the GWB Archives. Original Author: Mark Treadwell

New on Geeks with Blogs

  • We Won The One Award I Actually Care About

    Full Scale made the Inc. 5000 for the fifth year straight, the 12th listing across my three companies. Here is why the one award you cannot buy is worth stopping for.

  • Your Customers Build the Features Now

    I let a tool I liked sit dead for a year rather than build the features I wanted. An MCP server meant I never had to, and your customers can do the same to your product.

  • Get the Size of a Directory in Linux the Easy Way

    du -sh for the quick answer, ncdu for the cleanup, df for the disk itself: every command for checking directory size in Linux, plus why du and df never agree.

  • Vim Search and Replace: The Ultimate Guide

    One :%s command replaces every match in a file before a find dialog would even open. The Vim substitute patterns worth the muscle memory: flags, ranges, capture groups, and multi-file edits.