I am very interested in in-depth help for creating custom controls. I have done some work with this in an effort to teach myself, but would like some insight into better ways. In particular I would like to have help in the following areas:

1) Drag and Drop
2) Hosting other controls
3) Coordinating information between controls or synchronizing information (See requirements below).
4) Painting controls
5) Adding pop up menus to custom or user controls
6) When to use custom and when to use user controls.

My particular control requirements are as follows:

I need a container that will hold a variable number of controls that might look similar to a gant chart. The top of this container would have a ruler that would show the position of the start and stop of any shading in the individual controls as each one is selected. I am looking for the best way to implement this. Particular questions would be:

a) Should the ruler be a separate control or part of the container?
b) How do I take care of the communication between the selected control and the ruler? (See 3 above) Delegates?

Asked by Eric Torola. Answered by the Wonk on March 12, 2003


In answer to your general plea for help in building custom controls, I've posted the latest draft of Chapter 8: Controls from my upcoming Windows Forms Programming for C# Programmers, coming in July for Addison-Wesley. This material is copyright (c) 2002-2003 by Chris Sells and not for redistribution.

In answer to your specific request, I definitely think that your ruler should be a separate control docked to the top of your container. In terms of communication between the container and the control, I recommend delegates and events, which you can read about in .NET Delegates: A C# Bedtime Story.


I have feedback on this Ask The Wonk answer