Library tutorials & articles
Introduction to Designers
- Introduction
- Getting Started
- Something More Useful
- Adding Verbs
Introduction
What are Designers?
Designers are the gateway between your user control and the developer at design time. Any control present on the design surface is fully compiled and sitting on a form just like it would be at runtime, only it has a designer applied to it.
How do they Work?
Designers subclass controls and only allow certain messages to get through. When you click on a button on a form at design time, for example, the button never receives the click message. Instead, the designer processes the message and the control is selected, just as you would expect.
There are a few kinds of designer that you may come across, but they all implement the IDesigner interface. This fairly simplistic interface defines only four members, but in reality when you implement a designer you will inherit from either ComponentDesigner or ControlDesigner.
What can I do with a Designer?
Some pretty cool stuff. If you enjoy writing controls as I do, designers are a godsend. I'm not exaggerating when I say that more than half the time spent developing a control for .net can be spent developing the design-time experience. In most cases you can get away without writing one at all, but having a designer for your control or component helps give it that professional polish that people expect from good controls.
An example of good designer usage is the .NET Tab Control. This familiar control uses a set of tabs to switch between several client areas, thus saving space on forms where a lot of information is needed. The TabControl itself has a designer, which allows the user to switch the visible tab at design time. Normally click messages wouldn't get through to the underlying control at design time, but with the aid of a designer this is possible.
The TabControl class adds TabPage instances to itself to host child controls. A TabPage doesn't do a lot more than inherit from ContainerControl so you can host controls on it. Or does it? In actual fact, the TabPage Designer class does more. For instance, it stops the user from being able to move the TabPage. It should stay stationary and be moved and sized by its parent TabControl, and the designer enforces that. Also, the designer listens for when the user selects the TabPage and deletes it, and notifies the parent TabControl so it can update its collection and interface.
Another example of designer usage is the TextBox control. Have you ever wondered how it stops the user from resizing it when its multiline property is set to False? Well, you probably haven't, but it's with a designer, and it's remarkably easy to achieve.
All the selecting, moving and resizing of controls you do at design time is handled by the designers that are part of the framework. Together with a bucket load of interfaces implemented by the host environment, you can create an extremely flexible and intuitive design time experience for a developer using one of your controls.
Related articles
Related discussion
-
hey developers out there
by pitsophera (0 replies)
-
How can i develop opc server using .net?
by vairajaig (1 replies)
-
Creating a Windows Service in VB.NET
by davidvanr (108 replies)
-
High-Performance .NET Application Development & Architecture
by Manjot Bawa (0 replies)
-
An Introduction to VB.NET and Database Programming
by carlosmen (14 replies)
Related podcasts
-
A Practical Look at Silverlight 2 Part 1
Now that Silverlight 2 is at the Olympics and making a big splash, we wanted to explore this fascinating technology more. Microsoft Silverlight 2 is a cross-browser, cross-platform, and cross-device plug-in for delivering the next generation of .NET based media experiences and rich interactive ap...
Events coming up
-
Mar
15
DevWeek 2010
London, United Kingdom
DevWeek is Europe’s leading independent conference for software developers, database professionals and IT architects, and features expert speakers on a wide range of topics, including .NET 4.0, Silverlight 3, WCF 4, Visual Studio 2010, REST, Windows Workflow 4, Thread Synchronization, ASP.NET 4.0, SQL Server 2008 R2, LINQ, Unit Testing, CLR & C# 4.0, .NET Patterns, WPF 4, F#, Windows Azure, ADO.NET, Entity Framework, Debugging, T-SQL Tips & Tricks, and more.
I'm just going through this article and I've found that the CanBeParentedTo is not called when the control is just dragged from the tool box. It is called only when the control is already sited on a form and then it is dragged into a Panel or GroupBox etc.
I think it's worth to mention it. I've just spent an hour experimenting
Arthur
This thread is for discussions of Introduction to Designers.