Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
4.67/5 (3 votes)
See more:
I'm currently developing my own TabControl and I am struggling to make it designer friendly.

My control is made of a class like this:
public class GlassTabControl : UserControl
{
    private GlassTabPageCollection _tabList = new GlassTabPageCollection();

    // the property
    [Browsable(true)]
    public GlassTabPageCollection TabPages 
    { 
        get { return _tabList; } 
        set { _tabList = value; } 
    }

}


After adding my GlassTabControl on a Form and adding a GlassTabPage to my collection through VS2010 designer I found the exact code in MyForm.Designer.cs:

//
// glassTabControl1
//
this.glassTabControl1.Location = new System.Drawing.Point(12, 80);
this.glassTabControl1.Name = "glassTabControl1";
this.glassTabControl1.Size = new System.Drawing.Size(352, 257);
this.glassTabControl1.TabIndex = 0;
this.glassTabControl1.TabMinimumHeight = 25;
new GlassTabControlUI.TabPagesCollection().Add(this.glassTabPage1);


As you can see the last line makes no sense and if I replace it with:
this.glassTabControl1.TabPages.Add(this.glassTabPage1);

works perfectly.

Sorry for such a long post and I'm eager to hear your opinion on why that code is generated.

PS: I tried cleaning the solution, restarting VS, etc.

Thanks,
Alex
Posted
Updated 8-Jun-11 14:35pm
v2
Comments
Sergey Alexandrovich Kryukov 8-Jun-11 20:46pm    
Very hard to say without having of all the code. I don't like that auto-generated code but never saw that is generated gibberish. May be you even discover a defect in Visual Studio and/or ComponentModel. My 5 for the question. Basically, I would try to simplify down the component in big chunks and see what's going on...
--SA

1 solution

Add the DesignerSerializationVisibility attribute:

C#
// the property
[Browsable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public GlassTabPageCollection TabPages 
{ 
  get { return _tabList; } 
  set { _tabList = value; } 
}


http://msdn.microsoft.com/en-us/library/system.componentmodel.designerserializationvisibilityattribute.aspx[^]
 
Share this answer
 
Comments
Alex Culea 9-Jun-11 13:05pm    
Your solution is the right answer to my problem, thanks a lot!
Sander Rossel 8-Jan-13 11:04am    
Exactly what I was looking for!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900