title: Expose A Property Of Type List<class> In VS Designer Limiting/Hiding Access To Members Or Show Property As Expandable Menu?
body: <p>I have created a custom tab control for my Windows application. The custom tab control extends
  System.Windows.Forms.TabControl. The reason why I created a custom tab control is so I can expose a property in the Visual Studio Properties window that allows me to define individual fonts for each tab page in the custom tab control. Here is a quick look at the class definition:</p>
  
  <pre><code>[ToolboxItem(true)]    
  public partial class CustomTabControl : System.Windows.Forms.TabControl
  </code></pre>
  
  <p>To store each individual name/font pair I created a nested class inside CustomTabControl:</p>
  
  <pre><code>[TypeConverter(typeof(TabFontConverter))]
  public class TabFont
  {
      public string Name { get; set; }
      public Font Font { get; set; }        
      public TabFont()
      {
      }        
      public TabFont(string name, Font font)
      {
          this.Name = name;
          this.Font = font;
      }
  }
  </code></pre>
  
  <p>(Note the use of the <em>TypeConverter</em> property above the TabFont class. I added this because somewhere I read online that this was required if I am going to expose this type in the Visual Studio designer.)</p>
  
  <p>Here is the converter class (which is also nested inside CustomTabControl):</p>
  
  <pre><code>public class TabFontConverter : TypeConverter
  {
      public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] filter)
      {
          return TypeDescriptor.GetProperties(value, filter);
      }
  
      public override bool GetPropertiesSupported(ITypeDescriptorContext context)
      {
          return true;
      }
  }
  </code></pre>
  
  <p>I defined a class variable to store the custom tab fonts as a List:</p>
  
  <pre><code>private List&lt;TabFont&gt; _CustomTabFonts = new List&lt;TabFont&gt;();
  </code></pre>
  
  <p>To populate this list, I added an event handler for <em>ControlAdded</em>:</p>
  
  <pre><code>this.ControlAdded += new ControlEventHandler(CustomTabControl_ControlAdded);
  </code></pre>
  
  <p>Here is how I populate the list inside the event handler:</p>
  
  <pre><code>private void CustomTabControl_ControlAdded(object sender, ControlEventArgs e)
  {
      if (e.Control.GetType() == typeof(TabPage))
      {
          TabPage newTabPage = (TabPage)e.Control;
          Font newTabPageFont = newTabPage.Font;
          _CustomTabFonts.Add(new TabFont(newTabPage.Text, newTabPageFont));
          e.Control.Font = newTabPageFont;
      }
  }
  </code></pre>
  
  <p>And finally to tie it all up I defined the following code allowing the Visual Studio designer to access/modify the custom tab font list:</p>
  
  <pre><code>[DefaultValue(typeof(List&lt;TabFont&gt;))]
  [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] 
  public List&lt;TabFont&gt; CustomTabFonts
  {
      get { return _CustomTabFonts; }
      set { _CustomTabFonts = value; }
  }
  </code></pre>
  
  <p>After rebuilding I switch back to the Visual Studio design view, added a CustomTabControl to my main form by dragging one from the Toolbox., then I added 2 tab pages named "Tab 1" and "Tab 2".</p>
  
  <p>This is what the properties box shows for my custom tab fonts property:</p>
  
  <p><img src="https://i.stack.imgur.com/2CYMg.png" alt="Custom Tab Fonts Property"></p>
  
  <p>Note that it shows the type as a Collection and provides a button [...] to click for editing. When I click the button here is what I see:</p>
  
  <p><img src="https://i.stack.imgur.com/EmzWI.png" alt="Custom Tab Fonts Property Editor"></p>
  
  <p>I have a couple questions regarding the property editor.</p>
  
  <ul>
  <li><p>The right side of the property editor shows both the Font and Name
  for the selected tab. I only want to be able to change the Font, not
  the name. How can I either hide the name field or at least make it
  read only? (I would prefer the name field not to show there at all
  because I don't want to be able to change it and it's also redundant
  because the names are already shown on the left side of the property
  editor.)</p></li>
  <li><p>The left side of the property editor shows the list of tabs which is
  exactly what I want. I do not, however, want to allow moving, adding,
  or removing any of these members. How can I either hide or disable
  the Move (up/down arrows) and Add/Remove buttons?</p></li>
  <li><p>The left side of the property editor has a heading named "Members".
  Can I change that to say whatever I want? Something like "Tab Pages",
  etc.</p></li>
  <li><p>The right side of the property editor has a heading named "Misc". Can
  I change that as well?</p></li>
  </ul>
  
  <p>Thank you very much.</p>
  
  <p>Jan</p>
  
  <p><strong>____UPDATE____</strong></p>
  
  <p>If there is a better/different way of doing what I am trying to do I am open to all suggestions. I am new to this and what I have done so far has been based on various results from different web sites.</p>
  
  <p>I would really like my property to appear in the designer similar to the way margins are shown. Instead of a popup window with a list of tab pages/properties I would like an expandable list with each list item being the tab name followed by the font, which you could then click to edit the font only. Something like the following:</p>
  
  <p><img src="https://i.stack.imgur.com/Ow5od.png" alt="Custom Tab Fonts Property Preferred"></p>