Adding Auto Format for ASP.NET Custom Controls Design Time

Back to design time support, but this time with ASP.NET server controls, most complex & simple controls built in the .NET framework are associated with an Auto Format.. link in the smart tag as the one shown in the figure, I showed in a previous post how to add links and properties to the smart tag of a control.

autoLink  [more]

Ok, now when clicking that link a new window is popped out and you get a list of predefined formats on the left and a preview panel in the right like this.


Of course if you want to implement these features you will not have to design a new windows form and deal with all the head ache for previewing and those. You only will need some basic steps, I will show next, Assuming you already have your own custom control ( I will just use a simple LabelEx control for this sample);

1- Define your designer.

2- override the AutoFormats property and return some DesignerAutoFormats, to be used.

3- Define a custom DesignerAutoFormat, which comes with an abstract Apply method, which is called when trying to apply a format on the preview control.

4- And don’t forget to decorate the control with the designer attribute

And now everything is set and you have your own auto formats.

Default format reddish auto format Blueish auto format

Here is the code and Happy Coding…

3 thoughts on “Adding Auto Format for ASP.NET Custom Controls Design Time”

  1. Impressive – I didn´t thought about this, because I was sure it´ll be complicated. Thanks for clarifying this

Leave a Reply

Your email address will not be published. Required fields are marked *