Custom Controls Design Time Support Part 14: Extra Property Tab

by Amr Elsehemy 8. February 2008 18: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)

Currently rated 5.0 by 4 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

Design Time Support

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen

About the author

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

Calendar

<<  August 2008  >>
MoTuWeThFrSaSu
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567

View posts in large calendar

RecentPosts