Custom Controls Design Time Support Part 14: Extra Property Tab

by Amr Elsehemy 8. February 2008 09:19

The default PropetryWindow in the visual studio shows 2 Tabs one for properties and another for events. If one day you thought that you have set of members might be Properties that you need to put them in an extra property tab then in this post you will learn how to put extra tabs.

When this can be useful?

After the ajax era has arrived and component authors started to build some ajax controls we usually see Properties named " ClientXXX " where xxx is the event name and these properties just appear in the properties tab while it would be more appropriate to show them in an extra tab say a Client side events. 

How Can you do it?

You need to follow some steps.

  1. Create a Custom Tab that extends the System.Windows.Forms.Design.PropertyTab
  2. override the GetProperties method to send back the selected properties
  3. override the TabName property to set the name of the tab.
  4. override the Bitmap property to set the image of the tab button.
  5. Mark the control/component with PropertyTabAttribute and pass the type of the new Custom Tab.

In code:

public class ExtraSuperTab : System.Windows.Forms.Design.PropertyTab
{
    public override PropertyDescriptorCollection GetProperties(object component, Attribute[] attributes)
    {
        PropertyDescriptor pd = TypeDescriptor.CreateProperty(component.GetType(), "XXX",typeof(int), new CategoryAttribute("Super Properties"));

        return (new PropertyDescriptorCollection(new PropertyDescriptor[]{pd}));
    }

    public override string TabName
    {
        get { return "Super Tab"; }
    }

    public override System.Drawing.Bitmap Bitmap
    {
        get
        {
            return (System.Drawing.Bitmap)System.Drawing.Image.FromFile(@"D:\icon.bmp");
        }
    }
}

And in the control don't forget the attribute

[PropertyTab(typeof(ExtraSuperTab), PropertyTabScope.Component)]
public partial class TestUserControl : UserControl

How it looks at the end in visual studio. 

Extra Property Tab 

TestUserControl.cs (1.37 kb)

Tags: , ,

Design Time Support

Comments are closed

About the author

Amr Elsehemy
MCSD C#.Net,
MCTS Sql 2005,
MCPD Enterprise
avatar
E-mail me Send mail

Calendar

<<  September 2010  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

View posts in large calendar